From: ageay Date: Thu, 24 Feb 2011 15:34:34 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~1051 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b2f7f1d78f725e802608c121ac064fbfa470d194;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 564622070..a5dbae15b 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -370,7 +370,7 @@ std::string MEDCouplingCMesh::simpleRepr() const ret << "Description of mesh : \"" << getDescription() << "\"\n"; int tmpp1,tmpp2; double tt=getTime(tmpp1,tmpp2); - ret << "Time attached to the mesh (unit) : " << tt << " (" << getTimeUnit() << ")\n"; + ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n"; ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n"; ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n"; if(_x_array) diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 0f0c418b2..991856018 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -260,7 +260,7 @@ std::string MEDCouplingExtrudedMesh::simpleRepr() const ret << "Description of mesh : \"" << getDescription() << "\"\n"; int tmpp1,tmpp2; double tt=getTime(tmpp1,tmpp2); - ret << "Time attached to the mesh (unit) : " << tt << " (" << getTimeUnit() << ")\n"; + ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n"; ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n"; ret << "Cell id where 1D mesh has been deduced : " << _cell_2D_id << "\n"; ret << "Number of cells : " << getNumberOfCells() << "(" << _mesh2D->getNumberOfCells() << "x" << _mesh1D->getNumberOfCells() << ")\n"; @@ -386,8 +386,7 @@ MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::buildOrthogonalField() const int MEDCouplingExtrudedMesh::getCellContainingPoint(const double *pos, double eps) const { - //not implemented yet - return -1; + throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::getCellContainingPoint : not implemented yet !"); } MEDCouplingExtrudedMesh::~MEDCouplingExtrudedMesh() diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 898b4d2b3..183dbb471 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -409,6 +409,29 @@ void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, arr->getTuple(id,res); } +DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +{ + std::vector elts,eltsIndex; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + int spaceDim=mesh->getSpaceDimension(); + int nbOfComponents=arr->getNumberOfComponents(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + ret->alloc(nbOfPoints,nbOfComponents); + double *ptToFill=ret->getPointer(); + for(int i=0;i=1) + arr->getTuple(elts[eltsIndex[i]],ptToFill); + else + { + std::ostringstream oss; oss << "Point #" << i << " with coordinates : ("; + std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator(oss,", ")); + oss << ") detected outside mesh : unable to apply P0::getValueOnMulti ! "; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret->incrRef(); + return ret; +} + /*! * Nothing to do. It's not a bug. */ @@ -516,9 +539,18 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(id); if(type!=INTERP_KERNEL::NORM_SEG2 && type!=INTERP_KERNEL::NORM_TRI3 && type!=INTERP_KERNEL::NORM_TETRA4) throw INTERP_KERNEL::Exception("P1 getValueOn is not specified for not simplex cells !"); + getValueInCell(mesh,id,arr,loc,res); +} + +/*! + * This method localizes a point defined by 'loc' in a cell with id 'cellId' into mesh 'mesh'. + * The result is put into res expected to be of size at least arr->getNumberOfComponents() + */ +void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const +{ std::vector conn; std::vector coo; - mesh->getNodeIdsOfCell(id,conn); + mesh->getNodeIdsOfCell(cellId,conn); for(std::vector::const_iterator iter=conn.begin();iter!=conn.end();iter++) mesh->getCoordinatesOfNode(*iter,coo); int spaceDim=mesh->getSpaceDimension(); @@ -526,19 +558,17 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co std::vector vec(nbOfNodes); for(int i=0;i tmp=new double[nbOfNodes]; INTERP_KERNEL::barycentric_coords(vec,loc,tmp); int sz=arr->getNumberOfComponents(); - double *tmp2=new double[sz]; + INTERP_KERNEL::AutoPtr tmp2=new double[sz]; std::fill(res,res+sz,0.); for(int i=0;igetTuple(conn[i],tmp2); - std::transform(tmp2,tmp2+sz,tmp2,std::bind2nd(std::multiplies(),tmp[i])); - std::transform(res,res+sz,tmp2,res,std::plus()); + arr->getTuple(conn[i],(double *)tmp2); + std::transform((double *)tmp2,((double *)tmp2)+sz,(double *)tmp2,std::bind2nd(std::multiplies(),tmp[i])); + std::transform(res,res+sz,(double *)tmp2,res,std::plus()); } - delete [] tmp; - delete [] tmp2; } void MEDCouplingFieldDiscretizationP1::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const @@ -550,6 +580,29 @@ void MEDCouplingFieldDiscretizationP1::getValueOnPos(const DataArrayDouble *arr, arr->getTuple(id,res); } +DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +{ + std::vector elts,eltsIndex; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + int spaceDim=mesh->getSpaceDimension(); + int nbOfComponents=arr->getNumberOfComponents(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + ret->alloc(nbOfPoints,nbOfComponents); + double *ptToFill=ret->getPointer(); + for(int i=0;i=1) + getValueInCell(mesh,elts[eltsIndex[i]],arr,loc+i*spaceDim,ptToFill+i*nbOfComponents); + else + { + std::ostringstream oss; oss << "Point #" << i << " with coordinates : ("; + std::copy(loc+i*spaceDim,loc+(i+1)*spaceDim,std::ostream_iterator(oss,", ")); + oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! "; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret->incrRef(); + return ret; +} + void MEDCouplingFieldDiscretizationP1::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, DataArrayDouble *arr) const { renumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,arr,"Node"); @@ -948,6 +1001,11 @@ void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *a throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); } +DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +{ + throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented yet for gauss points !"); +} + MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { throw INTERP_KERNEL::Exception("Not implemented yet !"); @@ -1345,6 +1403,11 @@ void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); } +DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +{ + throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented for Gauss NE !"); +} + MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { throw INTERP_KERNEL::Exception("Not implemented yet !"); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 2f543fe96..df6ba297e 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM virtual MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const = 0; virtual void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const = 0; virtual void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const = 0; + virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const = 0; virtual MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const = 0; virtual void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const = 0; virtual void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const = 0; @@ -113,6 +114,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; 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; + DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; @@ -140,10 +142,13 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; 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; + DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; + protected: + void getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const; public: static const char REPR[]; static const TypeOfField TYPE; @@ -198,6 +203,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; 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; + DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; @@ -250,6 +256,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; 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; + DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 870c27c6c..6ba066f22 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -734,6 +734,15 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) con _type->getValueOn(arr,_mesh,spaceLoc,res); } +/*! + * Returns a newly allocated array with 'nbOfPoints' tuples and nb of components equal to 'this->getNumberOfComponents()'. + */ +DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *arr=_time_discr->getArray(); + return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints); +} + /*! * Returns value of 'this' on time 'time' of point 'spaceLoc' using spatial discretization. * If 'time' is not covered by this->_time_discr an exception will be thrown. diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index aa6987ccc..177075c03 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -102,6 +102,7 @@ namespace ParaMEDMEM void getValueOnPos(int i, int j, int k, double *res) const throw(INTERP_KERNEL::Exception); void getValueOn(const double *spaceLoc, double *res) const throw(INTERP_KERNEL::Exception); void getValueOn(const double *spaceLoc, double time, double *res) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getValueOnMulti(const double *spaceLoc, int nbOfPoints) const throw(INTERP_KERNEL::Exception); //! \b temporary void applyLin(double a, double b, int compoId); MEDCouplingFieldDouble &operator=(double value) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bb57d0dea..80c2aa6a6 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2732,6 +2732,7 @@ void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception) work[i]=work[i-1]+tmp; tmp=tmp2; } + declareAsNew(); } /*! diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 711a6400c..cdb0cfdf4 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -266,3 +266,29 @@ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, cons { return mesh1->mergeMyselfWith(mesh2); } + +void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const +{ + int ret=getCellContainingPoint(pos,eps); + elts.push_back(ret); +} + +void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const +{ + eltsIndex.resize(nbOfPoints+1); + eltsIndex[0]=0; + elts.clear(); + int spaceDim=getSpaceDimension(); + const double *work=pos; + for(int i=0;i=0) + { + elts.push_back(ret); + eltsIndex[i+1]=eltsIndex[i]+1; + } + else + eltsIndex[i+1]=eltsIndex[i]; + } +} diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 1ec2652a2..6303f0fe5 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -88,6 +88,8 @@ namespace ParaMEDMEM 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 void getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const; + virtual void getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const; virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const; virtual MEDCouplingFieldDouble *fillFromAnalytic2(TypeOfField t, int nbOfComp, const char *func) const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 1849ee8a4..d3b4f7b19 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1478,7 +1478,7 @@ std::string MEDCouplingUMesh::simpleRepr() const ret << "Description of mesh : \"" << getDescription() << "\"\n"; int tmpp1,tmpp2; double tt=getTime(tmpp1,tmpp2); - ret << "Time attached to the mesh (unit) : " << tt << " (" << getTimeUnit() << ")\n"; + ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n"; ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n"; ret << "Mesh dimension : " << _mesh_dim << "\nSpace dimension : "; if(_coords!=0) diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index f09efe658..877b7e2c6 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -459,6 +459,5 @@ DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const int MEDCouplingUMeshDesc::getCellContainingPoint(const double *pos, double eps) const { - //not implemented yet. - return -1; + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getCellContainingPoint : not implemented yet !"); } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index dda08257a..e37a6047a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -27,6 +27,7 @@ namespace ParaMEDMEM { + class DataArrayDouble; class MEDCouplingUMesh; class MEDCouplingFieldDouble; class MEDCouplingMultiFields; @@ -203,6 +204,11 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFillFromAnalyticTwo1 ); CPPUNIT_TEST( testFillFromAnalyticThree1 ); CPPUNIT_TEST( testDAUnitVar1 ); + CPPUNIT_TEST( testGaussCoordinates1 ); + //CPPUNIT_TEST( testP2Localization1 ); not implemented yet + CPPUNIT_TEST( testGetValueOn2 ); + CPPUNIT_TEST( testDAIGetIdsNotEqual1 ); + CPPUNIT_TEST( testDAIComputeOffsets1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -432,6 +438,11 @@ namespace ParaMEDMEM void testFillFromAnalyticTwo1(); void testFillFromAnalyticThree1(); void testDAUnitVar1(); + void testGaussCoordinates1(); + void testP2Localization1(); + void testGetValueOn2(); + void testDAIGetIdsNotEqual1(); + void testDAIComputeOffsets1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); @@ -525,6 +536,11 @@ namespace ParaMEDMEM static MEDCouplingUMesh *build2DTargetMesh_3(); static MEDCouplingUMesh *build3DTargetMesh_3(); static MEDCouplingUMesh *build2DTargetMesh_4(); + static MEDCouplingUMesh *build1DMultiTypes_1(); + static MEDCouplingUMesh *build2DMultiTypes_1(); + static MEDCouplingUMesh *build3DMultiTypes_1(); + static MEDCouplingUMesh *buildHexa8Mesh_1(); + static DataArrayDouble *buildCoordsForMultiTypes_1(); static MEDCouplingMultiFields *buildMultiFields_1(); static std::vector buildMultiFields_2(); static double sumAll(const std::vector< std::map >& matrix); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx index a095d4846..526668689 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx @@ -982,6 +982,156 @@ std::vector MEDCouplingBasicsTest::buildMultiFields_2( return fs; } +MEDCouplingUMesh *MEDCouplingBasicsTest::build1DMultiTypes_1() +{ + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Multi1DMesh",1); + DataArrayDouble *coo=buildCoordsForMultiTypes_1(); + const int conn[5]={0,2, 0,2,1}; + mesh->allocateCells(2); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+2); + mesh->finishInsertingCells(); + mesh->setCoords(coo); + coo->decrRef(); + return mesh; +} + +MEDCouplingUMesh *MEDCouplingBasicsTest::build2DMultiTypes_1() +{ + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Multi2DMesh",2); + DataArrayDouble *coo=buildCoordsForMultiTypes_1(); + const int conn[21]={3,4,5, 3,4,5,6,7,8, 0,9,10,11, 0,9,10,11,12,13,14,15}; + mesh->allocateCells(4); + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,conn+3); + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+9); + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,conn+13); + mesh->finishInsertingCells(); + mesh->setCoords(coo); + coo->decrRef(); + return mesh; +} + +MEDCouplingUMesh *MEDCouplingBasicsTest::build3DMultiTypes_1() +{ + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Multi3DMesh",3); + DataArrayDouble *coo=buildCoordsForMultiTypes_1(); + const int conn[81]={0,16,17,18, + 0,16,17,18,19,20,21,22,23,24, + 0,11,10,9,25, + 0,11,10,9,25,15,14,13,12,26,27,28,29, + 0,30,31,32,33,34, + 0,30,31,32,33,34,35,36,37,38,39,40,41,42,43, + 0,9,10,11,44,45,46,47, + 0,9,10,11,44,45,46,47,12,13,14,15,48,49,50,51,52,53,54,55 }; + mesh->allocateCells(8); + mesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_TETRA10,10,conn+4); + mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,conn+14); + mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA13,13,conn+19); + mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+32); + mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA15,15,conn+38); + mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+53); + mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA20,20,conn+61); + mesh->finishInsertingCells(); + mesh->setCoords(coo); + coo->decrRef(); + return mesh; +} + +DataArrayDouble *MEDCouplingBasicsTest::buildCoordsForMultiTypes_1() +{ + DataArrayDouble *coords=DataArrayDouble::New(); + coords->alloc(56,3); + coords->setInfoOnComponent(0,"X (cm)"); + coords->setInfoOnComponent(1,"Y (cm)"); + coords->setInfoOnComponent(2,"Z (cm)"); + const double data[168]={ + 0.0, 0.0, 0.0, //#0 + 0.5, 0.5, 0.5, //#1 + 1.0, 1.0, 1.0, //#2 + 1.0, 1.0, 0.0, //#3 + 2.0, 2.5, 0.0, //#4 + 6.0, 1.5, 0.0, //#5 + 1.0, 2.0, 0.0, //#6 + 4.5, 2.5, 0.0, //#7 + 4.0, 0.5, 0.0, //#8 + 0.0, 4.0, 0.0, //#9 + 4.0, 4.0, 0.0, //#10 + 4.0, 0.0, 0.0, //#11 + 0.0, 2.0, 0.0, //#12 + 2.0, 4.0, 0.0, //#13 + 4.0, 2.0, 0.0, //#14 + 2.0, 0.0, 0.0, //#15 + 0.0, 6.0, 0.0, //#16 + 3.0, 3.0, 0.0, //#17 + 1.3, 3.0, 3.0, //#18 + 0.0, 3.0, 0.0, //#19 + 1.5, 4.5, 0.0, //#20 + 1.5, 1.5, 0.0, //#21 + 0.65, 1.5, 1.5, //#22 + 0.65, 4.5, 1.5, //#23 + 2.15, 3.0, 1.5, //#24 + 2.0, 2.0, 2.0, //#25 + 3.0, 1.0, 1.0, //#26 + 3.0, 3.0, 1.0, //#27 + 1.0, 3.0, 1.0, //#28 + 1.0, 1.0, 1.0, //#29 + 0.0, 3.0, 0.0, //#30 + 2.0, 0.0, 0.0, //#31 + 0.0, 0.0, 6.0, //#32 + 0.0, 3.0, 6.0, //#33 + 3.0, 0.0, 6.0, //#34 + 0.0, 1.5, 0.0, //#35 + 1.5, 1.5, 0.0, //#36 + 1.5, 0.0, 0.0, //#37 + 0.0, 1.5, 6.0, //#38 + 1.5, 1.5, 6.0, //#39 + 1.5, 0.0, 6.0, //#40 + 0.0, 0.0, 3.0, //#41 + 0.0, 3.0, 3.0, //#42 + 3.0, 0.0, 3.0, //#43 + 0.0, 0.0, 4.0, //#44 + 0.0, 4.0, 4.0, //#45 + 4.0, 4.0, 4.0, //#46 + 4.0, 0.0, 4.0, //#47 + 0.0, 2.0, 4.0, //#48 + 2.0, 4.0, 4.0, //#49 + 4.0, 2.0, 4.0, //#50 + 2.0, 0.0, 4.0, //#51 + 0.0, 0.0, 2.0, //#52 + 0.0, 4.0, 2.0, //#53 + 4.0, 4.0, 2.0, //#54 + 4.0, 0.0, 2.0 //#55 + }; + std::copy(data,data+168,coords->getPointer()); + return coords; +} + +MEDCouplingUMesh *MEDCouplingBasicsTest::buildHexa8Mesh_1() +{ + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Hexa8Only",3); + DataArrayDouble *coo=DataArrayDouble::New(); + const double coords[81]={0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.5, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 0.5, 1.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.5, 1.0, 0.5, 0.5, 1.0, 1.0, 0.5, 1.0, 0.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0}; + coo->alloc(27,3); + std::copy(coords,coords+81,coo->getPointer()); + const int conn[64]={3,12,13,4,0,9,10,1, + 4,13,14,5,1,10,11,2, + 6,15,16,7,3,12,13,4, + 7,16,17,8,4,13,14,5, + 12,21,22,13,9,18,19,10, + 13,22,23,14,10,19,20,11, + 15,24,25,16,12,21,22,13, + 16,25,26,17,13,22,23,14}; + mesh->allocateCells(8); + for(int i=0;i<8;i++) + mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8*i); + mesh->finishInsertingCells(); + mesh->setCoords(coo); + coo->decrRef(); + return mesh; +} + double MEDCouplingBasicsTest::sumAll(const std::vector< std::map >& matrix) { double ret=0.; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index e99faae89..4ac586632 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -259,6 +259,13 @@ void MEDCouplingBasicsTest::testMeshSetTime1() CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12)); m2->setTime(3.14,6,7); CPPUNIT_ASSERT(m1->isEqual(m2,1e-12)); + m1->setTimeUnit("ms"); + CPPUNIT_ASSERT(std::string(m1->getTimeUnit())=="ms"); + m1->setTimeUnit("us"); + CPPUNIT_ASSERT(std::string(m1->getTimeUnit())=="us"); + CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12)); + m2->setTimeUnit("us"); + CPPUNIT_ASSERT(m1->isEqual(m2,1e-12)); m2->setTime(3.14,6,8); CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12)); m2->setTime(3.14,7,7); @@ -478,3 +485,247 @@ void MEDCouplingBasicsTest::testDAUnitVar1() da->decrRef(); } +void MEDCouplingBasicsTest::testGaussCoordinates1() +{ + //Testing 1D cell types + MEDCouplingUMesh *m1=build1DMultiTypes_1(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME); + f->setMesh(m1); + std::vector wg1(1); wg1[0]=0.3; + std::vector gsCoo1(1); gsCoo1[0]=0.2; + std::vector refCoo1(2); refCoo1[0]=-1.0; refCoo1[1]=1.0; + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_SEG2,refCoo1,gsCoo1,wg1); + std::vector wg2(wg1); + std::vector gsCoo2(1); gsCoo2[0]=0.2; + std::vector refCoo2(3); refCoo2[0]=-1.0; refCoo2[1]=1.0; refCoo2[2]=0.0; + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_SEG3,refCoo2,gsCoo2,wg2); + // + DataArrayDouble *resToTest=f->getLocalizationOfDiscr(); + CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(2,resToTest->getNumberOfTuples()); + const double expected1[6]={0.6,0.6,0.6, 0.6,0.6,0.6}; + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],resToTest->getIJ(0,i),1e-14); + resToTest->decrRef(); + // + m1->decrRef(); + f->decrRef(); + //Testing 2D cell types + MEDCouplingUMesh *m2=build2DMultiTypes_1(); + f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME); + f->setMesh(m2); + std::vector wg3(2); wg3[0]=0.3; wg3[1]=0.3; + const double tria3CooGauss[4]={ 0.1, 0.8, 0.2, 0.7 }; + std::vector gsCoo3(tria3CooGauss,tria3CooGauss+4); + const double tria3CooRef[6]={ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 }; + std::vector refCoo3(tria3CooRef,tria3CooRef+6); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,refCoo3,gsCoo3,wg3); + std::vector wg4(3); wg4[0]=0.3; wg4[1]=0.3; wg4[2]=0.3; + const double tria6CooGauss[6]={ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 }; + std::vector gsCoo4(tria6CooGauss,tria6CooGauss+6); + const double tria6CooRef[12]={0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5}; + std::vector refCoo4(tria6CooRef,tria6CooRef+12); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,refCoo4,gsCoo4,wg4); + std::vector wg5(4); wg5[0]=0.3; wg5[1]=0.3; wg5[2]=0.3; wg5[3]=0.3; + const double quad4CooGauss[8]={ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 }; + std::vector gsCoo5(quad4CooGauss,quad4CooGauss+8); + const double quad4CooRef[8]={-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0}; + std::vector refCoo5(quad4CooRef,quad4CooRef+8); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,refCoo5,gsCoo5,wg5); + std::vector wg6(4); wg6[0]=0.3; wg6[1]=0.3; wg6[2]=0.3; wg6[3]=0.3; + const double quad8CooGauss[8]={ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 }; + std::vector gsCoo6(quad8CooGauss,quad8CooGauss+8); + const double quad8CooRef[16]={ -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 0.0}; + std::vector refCoo6(quad8CooRef,quad8CooRef+16); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD8,refCoo6,gsCoo6,wg6); + // + resToTest=f->getLocalizationOfDiscr(); + CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(13,resToTest->getNumberOfTuples());//2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8 + const double expected2[39]={5.1,1.55,0.0, 4.7,1.65,0.0, //TRI3 + 2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,//TRI6 + 2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,//QUAD4 + 2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 };//QUAD8 + for(int i=0;i<39;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],resToTest->getIJ(0,i),1e-14); + resToTest->decrRef(); + // + m2->decrRef(); + f->decrRef(); + //Testing 3D cell types + MEDCouplingUMesh *m3=build3DMultiTypes_1(); + f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME); + f->setMesh(m3); + // + std::vector wg7(1); wg7[0]=0.3; + const double tetra4CooGauss[3]={0.34, 0.16, 0.21}; + std::vector gsCoo7(tetra4CooGauss,tetra4CooGauss+3); + const double tetra4CooRef[12]={0.0,1.0,0.0, 0.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,0.0}; + std::vector refCoo7(tetra4CooRef,tetra4CooRef+12); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TETRA4,refCoo7,gsCoo7,wg7); + std::vector wg8(1); wg8[0]=0.3; + const double tetra10CooGauss[3]={0.2, 0.3, 0.1}; + std::vector gsCoo8(tetra10CooGauss,tetra10CooGauss+3); + const double tetra10CooRef[30]={0.0,1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0, 1.0,0.0,0.0, 0.0,0.5,0.0, 0.0,0.0,0.5, 0.0,0.5,0.5, 0.5,0.5,0.0, 0.5,0.0,0.0, 0.5,0.0,0.5}; + std::vector refCoo8(tetra10CooRef,tetra10CooRef+30); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TETRA10,refCoo8,gsCoo8,wg8); + std::vector wg9(1); wg9[0]=0.3; + const double pyra5CooGauss[3]={0.2, 0.3, 0.1}; + std::vector gsCoo9(pyra5CooGauss,pyra5CooGauss+3); + const double pyra5CooRef[15]={1.0,0.0,0.0, 0.0,1.0,0.0, -1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,1.0}; + std::vector refCoo9(pyra5CooRef,pyra5CooRef+15); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PYRA5,refCoo9,gsCoo9,wg9); + std::vector wg10(1); wg10[0]=0.3; + const double pyra13CooGauss[3]={0.1, 0.2, 0.7}; + std::vector gsCoo10(pyra13CooGauss,pyra13CooGauss+3); + const double pyra13CooRef[39]={1.0,0.0,0.0, 0.0,1.0,0.0,-1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,1.0,0.5,0.5,0.0,-0.5,0.5,0.0,-0.5,-0.5,0.0,0.5,-0.5,0.0,0.5,0.0,0.5,0.0,0.5,0.5,-0.5,0.0,0.5,0.0,-0.5,0.5}; + std::vector refCoo10(pyra13CooRef,pyra13CooRef+39); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PYRA13,refCoo10,gsCoo10,wg10); + std::vector wg11(1); wg11[0]=0.3; + const double penta6CooGauss[3]={0.2, 0.3, 0.1}; + std::vector gsCoo11(penta6CooGauss,penta6CooGauss+3); + const double penta6CooRef[18]={-1.0,1.0,0.0,-1.0,-0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0}; + std::vector refCoo11(penta6CooRef,penta6CooRef+18); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PENTA6,refCoo11,gsCoo11,wg11); + std::vector wg12(1); wg12[0]=0.3; + const double penta15CooGauss[3]={0.2, 0.3,0.15}; + std::vector gsCoo12(penta15CooGauss,penta15CooGauss+3); + const double penta15CooRef[45]={-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.0,0.5,0.5,-1.0,0.0,0.5,-1.0,0.5,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.5,0.5,1.0,0.0, 0.5,1.0,0.5,0.0}; + std::vector refCoo12(penta15CooRef,penta15CooRef+45); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PENTA15,refCoo12,gsCoo12,wg12); + std::vector wg13(1); wg13[0]=0.3; + const double hexa8CooGauss[3]={0.2,0.3,0.15}; + std::vector gsCoo13(hexa8CooGauss,hexa8CooGauss+3); + const double hexa8CooRef[24]={-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0}; + std::vector refCoo13(hexa8CooRef,hexa8CooRef+24); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_HEXA8,refCoo13,gsCoo13,wg13); + std::vector wg14(1); wg14[0]=0.3; + const double hexa20CooGauss[3]={0.11,0.3,0.55}; + std::vector gsCoo14(hexa20CooGauss,hexa20CooGauss+3); + const double hexa20CooRef[60]={-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0,0.0,-1.0,-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,-1.0,0.0,-1.0,-1.0,-1.0,0.0,1.0,-1.0,0.0,1.0,1.0,0.0,-1.0,1.0,0.0,0.0,-1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,-1.0,0.0,1.0}; + std::vector refCoo14(hexa20CooRef,hexa20CooRef+60); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_HEXA20,refCoo14,gsCoo14,wg14); + // + resToTest=f->getLocalizationOfDiscr(); + CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(8,resToTest->getNumberOfTuples());//2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8 + const double expected3[24]={1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255}; + for(int i=0;i<24;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],resToTest->getIJ(0,i),1e-14); + resToTest->decrRef(); + // + m3->decrRef(); + f->decrRef(); +} + +/*! + * Not activated test ! To be implemented ! WARNING Hexa8 should be replaced by Quad8... + */ +void MEDCouplingBasicsTest::testP2Localization1() +{ + MEDCouplingUMesh *m=buildHexa8Mesh_1(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME); + DataArrayDouble *da=DataArrayDouble::New(); + const double vals1[27]={1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0,1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0,1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0}; + da->alloc(27,1); + std::copy(vals1,vals1+27,da->getPointer()); + f->setMesh(m); + f->setArray(da); + da->decrRef(); + // + const double point1[3]={0.25,0.75,0.25}; + //const double points1[6]={0.25,0.75,0.25,1.0,1.0,1.0}; + double res1[3]; + f->getValueOn(point1,res1); + // + f->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testGetValueOn2() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); + f->setMesh(m); + DataArrayDouble *arr=DataArrayDouble::New(); + int nbOfCells=m->getNumberOfCells(); + arr->alloc(nbOfCells,3); + f->setArray(arr); + arr->decrRef(); + const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.}; + std::copy(values1,values1+15,arr->getPointer()); + const double loc[10]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45}; + f->checkCoherency(); + DataArrayDouble *locs=f->getValueOnMulti(loc,5); + CPPUNIT_ASSERT_EQUAL(5,locs->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,locs->getNumberOfComponents()); + for(int j=0;j<15;j++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[j],locs->getIJ(0,j),1e-12); + locs->decrRef(); + f->decrRef(); + // Testing ON_NODES + f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME); + f->setMesh(m); + arr=DataArrayDouble::New(); + int nbOfNodes=m->getNumberOfNodes(); + arr->alloc(nbOfNodes,3); + f->setArray(arr); + arr->decrRef(); + const double values2[27]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.}; + std::copy(values2,values2+27,arr->getPointer()); + const double loc2[8]={0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432}; + const double expected2[12]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124, 9.0272, 109.0272, 10009.0272, 9.0272, 109.0272, 10009.0272}; + f->checkCoherency(); + locs=f->getValueOnMulti(loc2,4); + CPPUNIT_ASSERT_EQUAL(4,locs->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,locs->getNumberOfComponents()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],locs->getIJ(0,i),1e-12); + f->decrRef(); + locs->decrRef(); + // + m->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIGetIdsNotEqual1() +{ + DataArrayInt *d=DataArrayInt::New(); + const int vals1[10]={2,3,5,6,8,5,5,6,1,-5}; + d->alloc(10,1); + std::copy(vals1,vals1+10,d->getPointer()); + DataArrayInt *d2=d->getIdsNotEqual(5); + CPPUNIT_ASSERT_EQUAL(7,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,d2->getNumberOfComponents()); + const int expected1[7]={0,1,3,4,7,8,9}; + for(int i=0;i<7;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],d2->getIJ(0,i)); + d->rearrange(2); + CPPUNIT_ASSERT_THROW(d->getIdsNotEqual(5),INTERP_KERNEL::Exception); + const int vals2[3]={-4,5,6}; + std::vector vals3(vals2,vals2+3); + d->rearrange(1); + DataArrayInt *d3=d->getIdsNotEqualList(vals3); + CPPUNIT_ASSERT_EQUAL(5,d3->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,d3->getNumberOfComponents()); + const int expected2[5]={0,1,4,8,9}; + for(int i=0;i<5;i++) + CPPUNIT_ASSERT_EQUAL(expected2[i],d3->getIJ(0,i)); + d3->decrRef(); + d->decrRef(); + d2->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIComputeOffsets1() +{ + DataArrayInt *d=DataArrayInt::New(); + const int vals1[6]={3,5,1,2,0,8}; + const int expected1[6]={0,3,8,9,11,11}; + d->alloc(6,1); + std::copy(vals1,vals1+6,d->getPointer()); + d->computeOffsets(); + CPPUNIT_ASSERT_EQUAL(6,d->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents()); + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],d->getIJ(0,i)); + d->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 18dfb6980..8b4e725da 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -72,6 +72,7 @@ using namespace INTERP_KERNEL; %feature("docstring"); %newobject ParaMEDMEM::MEDCouplingField::buildMeasureField; +%newobject ParaMEDMEM::MEDCouplingField::getLocalizationOfDiscr; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getArray; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getEndArray; @@ -109,6 +110,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh; %newobject ParaMEDMEM::MEDCouplingFieldDouble::deepCpy; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::getValueOnMulti; %newobject ParaMEDMEM::MEDCouplingFieldTemplate::New; %newobject ParaMEDMEM::DataArrayInt::New; %newobject ParaMEDMEM::DataArrayInt::convertToDblArr; @@ -126,7 +128,9 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2O; %newobject ParaMEDMEM::DataArrayInt::invertArrayN2O2O2N; %newobject ParaMEDMEM::DataArrayInt::getIdsEqual; +%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqual; %newobject ParaMEDMEM::DataArrayInt::getIdsEqualList; +%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList; %newobject ParaMEDMEM::DataArrayInt::Aggregate; %newobject ParaMEDMEM::DataArrayInt::Meld; %newobject ParaMEDMEM::DataArrayInt::BuildUnion; @@ -345,6 +349,35 @@ namespace ParaMEDMEM delete [] pos; return ret; } + + PyObject *getCellsContainingPoints(PyObject *p, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr pos=convertPyToNewDblArr2(p,&sz); + std::vector elts,eltsIndex; + self->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + d0->alloc(elts.size(),1); + d1->alloc(eltsIndex.size(),1); + std::copy(elts.begin(),elts.end(),d0->getPointer()); + std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + d0->incrRef(); + d1->incrRef(); + return ret; + } + + PyObject *getCellsContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr pos=convertPyToNewDblArr2(p,&sz); + std::vector elts; + self->getCellsContainingPoint(pos,eps,elts); + return convertIntArrToPyList2(elts); + } void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception) { @@ -874,37 +907,6 @@ namespace ParaMEDMEM return ret; } - PyObject *getCellsContainingPoints(PyObject *p, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception) - { - int sz; - double *pos=convertPyToNewDblArr2(p,&sz); - std::vector elts,eltsIndex; - self->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); - delete [] pos; - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - d0->alloc(elts.size(),1); - d1->alloc(eltsIndex.size(),1); - std::copy(elts.begin(),elts.end(),d0->getPointer()); - std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); - return ret; - } - - PyObject *getCellsContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception) - { - int sz; - double *pos=convertPyToNewDblArr2(p,&sz); - std::vector elts; - self->getCellsContainingPoint(pos,eps,elts); - delete [] pos; - return convertIntArrToPyList2(elts); - } - static PyObject *MergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) { std::vector meshes; @@ -1836,6 +1838,7 @@ namespace ParaMEDMEM TypeOfField getTypeOfField() const throw(INTERP_KERNEL::Exception); NatureOfField getNature() const throw(INTERP_KERNEL::Exception); virtual void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); + DataArrayDouble *getLocalizationOfDiscr() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDiscretization *getDiscretization() const throw(INTERP_KERNEL::Exception); int getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception); @@ -2037,6 +2040,39 @@ namespace ParaMEDMEM self->getValueOn(spaceLoc,res); return convertDblArrToPyList(res,sz); } + + DataArrayDouble *getValueOnMulti(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewDblArr2(li,&size); + int spaceDim=self->getMesh()->getSpaceDimension(); + int nbOfPoints=size/spaceDim; + if(size%spaceDim!=0) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be a multiple of self.getMesh().getSpaceDimension() !"); + } + return self->getValueOnMulti(tmp,nbOfPoints); + } + else + { + DataArrayDouble *da2=reinterpret_cast< DataArrayDouble * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayDouble instance expected !"); + da2->checkAllocated(); + int size=da2->getNumberOfTuples(); + int nbOfCompo=da2->getNumberOfComponents(); + if(nbOfCompo!=self->getMesh()->getSpaceDimension()) + { + throw INTERP_KERNEL::Exception("Invalid DataArrayDouble nb of components ! Expected same as self.getMesh().getSpaceDimension() !"); + } + return self->getValueOnMulti(da2->getConstPointer(),size); + } + } + PyObject *getValueOn(PyObject *sl, double time) const throw(INTERP_KERNEL::Exception) { int sz; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index efcb3364b..ee379906f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6154,6 +6154,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(not m1.isEqual(m2,1e-12)); m2.setTime(3.14,6,7); self.assertTrue(m1.isEqual(m2,1e-12)); + m1.setTimeUnit("ms"); + self.assertTrue(m1.getTimeUnit()=="ms"); + m1.setTimeUnit("us"); + self.assertTrue(m1.getTimeUnit()=="us"); + self.assertTrue(not m1.isEqual(m2,1e-12)); + m2.setTimeUnit("us"); + self.assertTrue(m1.isEqual(m2,1e-12)); m2.setTime(3.14,6,8); self.assertTrue(not m1.isEqual(m2,1e-12)); m2.setTime(3.14,7,7); @@ -6347,6 +6354,209 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(vs[1]=="m^2/kJ"); self.assertTrue(vs[2]=="MW/s"); pass + + def testGaussCoordinates1(self): + #Testing 1D cell types + m1=MEDCouplingDataForTest.build1DMultiTypes_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME); + f.setMesh(m1); + wg1=[0.3]; + gsCoo1=[0.2]; + refCoo1=[-1.0,1.0]; + f.setGaussLocalizationOnType(NORM_SEG2,refCoo1,gsCoo1,wg1); + wg2=wg1; + gsCoo2=[0.2]; + refCoo2=[-1.0,1.0,0.0]; + f.setGaussLocalizationOnType(NORM_SEG3,refCoo2,gsCoo2,wg2); + # + resToTest=f.getLocalizationOfDiscr(); + self.assertEqual(3,resToTest.getNumberOfComponents()); + self.assertEqual(2,resToTest.getNumberOfTuples()); + expected1=[0.6,0.6,0.6, 0.6,0.6,0.6] + for i in xrange(6): + self.assertAlmostEqual(expected1[i],resToTest.getIJ(0,i),14); + pass + # + #Testing 2D cell types + m2=MEDCouplingDataForTest.build2DMultiTypes_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME); + f.setMesh(m2); + wg3=[0.3,0.3]; + tria3CooGauss=[ 0.1, 0.8, 0.2, 0.7 ] + gsCoo3=tria3CooGauss + tria3CooRef=[ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 ] + refCoo3=tria3CooRef; + f.setGaussLocalizationOnType(NORM_TRI3,refCoo3,gsCoo3,wg3); + wg4=[0.3,0.3,0.3]; + tria6CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 ] + gsCoo4=tria6CooGauss; + tria6CooRef=[0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5] + refCoo4=tria6CooRef; + f.setGaussLocalizationOnType(NORM_TRI6,refCoo4,gsCoo4,wg4); + wg5=[0.3,0.3,0.3,0.3]; + quad4CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 ] + gsCoo5=quad4CooGauss; + quad4CooRef=[-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0] + refCoo5=quad4CooRef; + f.setGaussLocalizationOnType(NORM_QUAD4,refCoo5,gsCoo5,wg5); + wg6=[0.3,0.3,0.3,0.3]; + quad8CooGauss=[ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 ] + gsCoo6=quad8CooGauss; + quad8CooRef=[ -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 0.0] + refCoo6=quad8CooRef; + f.setGaussLocalizationOnType(NORM_QUAD8,refCoo6,gsCoo6,wg6); + # + resToTest=f.getLocalizationOfDiscr(); + self.assertEqual(3,resToTest.getNumberOfComponents()); + self.assertEqual(13,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8 + expected2=[5.1,1.55,0.0, 4.7,1.65,0.0, + 2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,#TRI6 + 2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,#QUAD4 + 2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 ];#QUAD8 + for i in xrange(39): + self.assertAlmostEqual(expected2[i],resToTest.getIJ(0,i),14); + pass + # + #Testing 3D cell types + m3=MEDCouplingDataForTest.build3DMultiTypes_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME); + f.setMesh(m3); + # + wg7=[0.3]; + tetra4CooGauss=[0.34, 0.16, 0.21] + gsCoo7=tetra4CooGauss; + tetra4CooRef=[0.0,1.0,0.0, 0.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,0.0] + refCoo7=tetra4CooRef; + f.setGaussLocalizationOnType(NORM_TETRA4,refCoo7,gsCoo7,wg7); + wg8=[0.3]; + tetra10CooGauss=[0.2, 0.3, 0.1] + gsCoo8=tetra10CooGauss; + tetra10CooRef=[0.0,1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0, 1.0,0.0,0.0, 0.0,0.5,0.0, 0.0,0.0,0.5, 0.0,0.5,0.5, 0.5,0.5,0.0, 0.5,0.0,0.0, 0.5,0.0,0.5] + refCoo8=tetra10CooRef; + f.setGaussLocalizationOnType(NORM_TETRA10,refCoo8,gsCoo8,wg8); + wg9=[0.3]; + pyra5CooGauss=[0.2, 0.3, 0.1] + gsCoo9=pyra5CooGauss; + pyra5CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0, -1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,1.0] + refCoo9=pyra5CooRef; + f.setGaussLocalizationOnType(NORM_PYRA5,refCoo9,gsCoo9,wg9); + wg10=[0.3]; + pyra13CooGauss=[0.1, 0.2, 0.7] + gsCoo10=pyra13CooGauss; + pyra13CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0,-1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,1.0,0.5,0.5,0.0,-0.5,0.5,0.0,-0.5,-0.5,0.0,0.5,-0.5,0.0,0.5,0.0,0.5,0.0,0.5,0.5,-0.5,0.0,0.5,0.0,-0.5,0.5] + refCoo10=pyra13CooRef; + f.setGaussLocalizationOnType(NORM_PYRA13,refCoo10,gsCoo10,wg10); + wg11=[0.3]; + penta6CooGauss=[0.2, 0.3, 0.1] + gsCoo11=penta6CooGauss; + penta6CooRef=[-1.0,1.0,0.0,-1.0,-0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0] + refCoo11=penta6CooRef; + f.setGaussLocalizationOnType(NORM_PENTA6,refCoo11,gsCoo11,wg11); + wg12=[0.3]; + penta15CooGauss=[0.2, 0.3,0.15] + gsCoo12=penta15CooGauss; + penta15CooRef=[-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.0,0.5,0.5,-1.0,0.0,0.5,-1.0,0.5,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.5,0.5,1.0,0.0, 0.5,1.0,0.5,0.0] + refCoo12=penta15CooRef; + f.setGaussLocalizationOnType(NORM_PENTA15,refCoo12,gsCoo12,wg12); + wg13=[0.3]; + hexa8CooGauss=[0.2,0.3,0.15] + gsCoo13=hexa8CooGauss; + hexa8CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0] + refCoo13=hexa8CooRef; + f.setGaussLocalizationOnType(NORM_HEXA8,refCoo13,gsCoo13,wg13); + wg14=[0.3]; + hexa20CooGauss=[0.11,0.3,0.55] + gsCoo14=hexa20CooGauss; + hexa20CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0,0.0,-1.0,-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,-1.0,0.0,-1.0,-1.0,-1.0,0.0,1.0,-1.0,0.0,1.0,1.0,0.0,-1.0,1.0,0.0,0.0,-1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,-1.0,0.0,1.0] + refCoo14=hexa20CooRef; + f.setGaussLocalizationOnType(NORM_HEXA20,refCoo14,gsCoo14,wg14); + # + resToTest=f.getLocalizationOfDiscr(); + self.assertEqual(3,resToTest.getNumberOfComponents()); + self.assertEqual(8,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8 + expected3=[1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255] + for i in xrange(24): + self.assertAlmostEqual(expected3[i],resToTest.getIJ(0,i),14); + pass + # + pass + + def testGetValueOn2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f.setMesh(m); + arr=DataArrayDouble.New(); + nbOfCells=m.getNumberOfCells(); + f.setArray(arr); + values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.] + arr.setValues(values1,nbOfCells,3); + loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45] + f.checkCoherency(); + locs=f.getValueOnMulti(loc); + self.assertEqual(5,locs.getNumberOfTuples()); + self.assertEqual(3,locs.getNumberOfComponents()); + for j in xrange(15): + self.assertAlmostEqual(values1[j],locs.getIJ(0,j),12); + pass + # Testing ON_NODES + f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + f.setMesh(m); + arr=DataArrayDouble.New(); + nbOfNodes=m.getNumberOfNodes(); + f.setArray(arr); + values2=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.] + arr.setValues(values2,nbOfNodes,3); + loc2=[0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432] + expected2=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124, 9.0272, 109.0272, 10009.0272, 9.0272, 109.0272, 10009.0272] + f.checkCoherency(); + loc3=DataArrayDouble.New() + loc3.setValues(loc2,4,2); + locs=f.getValueOnMulti(loc3); + self.assertEqual(4,locs.getNumberOfTuples()); + self.assertEqual(3,locs.getNumberOfComponents()); + for i in xrange(12): + self.assertAlmostEqual(expected2[i],locs.getIJ(0,i),12); + pass + # + pass + + def testDAIGetIdsNotEqual1(self): + d=DataArrayInt.New(); + vals1=[2,3,5,6,8,5,5,6,1,-5] + d.setValues(vals1,10,1); + d2=d.getIdsNotEqual(5); + self.assertEqual(7,d2.getNumberOfTuples()); + self.assertEqual(1,d2.getNumberOfComponents()); + expected1=[0,1,3,4,7,8,9] + for i in xrange(7): + self.assertEqual(expected1[i],d2.getIJ(0,i)); + pass + d.rearrange(2); + self.assertRaises(InterpKernelException,d.getIdsNotEqual,5); + vals2=[-4,5,6] + vals3=vals2; + d.rearrange(1); + d3=d.getIdsNotEqualList(vals3); + self.assertEqual(5,d3.getNumberOfTuples()); + self.assertEqual(1,d3.getNumberOfComponents()); + expected2=[0,1,4,8,9] + for i in xrange(5): + self.assertEqual(expected2[i],d3.getIJ(0,i)); + pass + pass + + def testDAIComputeOffsets1(self): + d=DataArrayInt.New(); + vals1=[3,5,1,2,0,8] + expected1=[0,3,8,9,11,11] + d.setValues(vals1,6,1); + d.computeOffsets(); + self.assertEqual(6,d.getNumberOfTuples()); + self.assertEqual(1,d.getNumberOfComponents()); + for i in xrange(6): + self.assertEqual(expected1[i],d.getIJ(0,i)); + pass + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index 99299d48c..9607373a9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -430,6 +430,84 @@ class MEDCouplingDataForTest: f4.setName("f4"); return [f0,f1,f2,f3,f4] + def build1DMultiTypes_1(self): + mesh=MEDCouplingUMesh.New("Multi1DMesh",1); + coo=MEDCouplingDataForTest.buildCoordsForMultiTypes_1(); + conn=[0,2, 0,2,1] + mesh.allocateCells(2); + mesh.insertNextCell(NORM_SEG2,2,conn[0:2]) + mesh.insertNextCell(NORM_SEG3,3,conn[2:5]) + mesh.finishInsertingCells(); + mesh.setCoords(coo); + return mesh; + + def build2DMultiTypes_1(self): + mesh=MEDCouplingUMesh.New("Multi2DMesh",2); + coo=MEDCouplingDataForTest.buildCoordsForMultiTypes_1(); + conn=[3,4,5, 3,4,5,6,7,8, 0,9,10,11, 0,9,10,11,12,13,14,15] + mesh.allocateCells(4); + mesh.insertNextCell(NORM_TRI3,3,conn[0:3]) + mesh.insertNextCell(NORM_TRI6,6,conn[3:9]) + mesh.insertNextCell(NORM_QUAD4,4,conn[9:13]) + mesh.insertNextCell(NORM_QUAD8,8,conn[13:21]) + mesh.finishInsertingCells(); + mesh.setCoords(coo); + return mesh; + + def build3DMultiTypes_1(self): + mesh=MEDCouplingUMesh.New("Multi3DMesh",3); + coo=MEDCouplingDataForTest.buildCoordsForMultiTypes_1(); + conn=[0,16,17,18, + 0,16,17,18,19,20,21,22,23,24, + 0,11,10,9,25, + 0,11,10,9,25,15,14,13,12,26,27,28,29, + 0,30,31,32,33,34, + 0,30,31,32,33,34,35,36,37,38,39,40,41,42,43, + 0,9,10,11,44,45,46,47, + 0,9,10,11,44,45,46,47,12,13,14,15,48,49,50,51,52,53,54,55 ]; + mesh.allocateCells(8); + mesh.insertNextCell(NORM_TETRA4,4,conn[0:4]) + mesh.insertNextCell(NORM_TETRA10,10,conn[4:14]) + mesh.insertNextCell(NORM_PYRA5,5,conn[14:19]) + mesh.insertNextCell(NORM_PYRA13,13,conn[19:32]) + mesh.insertNextCell(NORM_PENTA6,6,conn[32:38]) + mesh.insertNextCell(NORM_PENTA15,15,conn[38:53]) + mesh.insertNextCell(NORM_HEXA8,8,conn[53:61]) + mesh.insertNextCell(NORM_HEXA20,20,conn[61:81]) + mesh.finishInsertingCells(); + mesh.setCoords(coo); + return mesh; + + def buildCoordsForMultiTypes_1(self): + coords=DataArrayDouble.New(); + data=[0.0,0.0,0.0, 0.5,0.5,0.5, 1.0,1.0,1.0, 1.0,1.0,0.0, 2.0,2.5,0.0, 6.0,1.5,0.0, 1.0,2.0,0.0, 4.5,2.5,0.0, 4.0,0.5,0.0, 0.0,4.0,0.0, 4.0,4.0,0.0, 4.0,0.0,0.0, 0.0,2.0,0.0, 2.0,4.0,0.0, 4.0,2.0,0.0, 2.0,0.0,0.0, 0.0,6.0,0.0, 3.0,3.0,0.0, 1.3,3.0,3.0, 0.0,3.0,0.0, 1.5,4.5,0.0, 1.5,1.5,0.0, 0.65,1.5,1.5, 0.65,4.5,1.5, 2.15,3.0,1.5, 2.0,2.0,2.0, 3.0,1.0,1.0, 3.0,3.0,1.0, 1.0,3.0,1.0, 1.0,1.0,1.0, 0.0,3.0,0.0, 2.0,0.0,0.0, 0.0,0.0,6.0, 0.0,3.0,6.0, 3.0,0.0,6.0, 0.0,1.5,0.0, 1.5,1.5,0.0, 1.5,0.0,0.0, 0.0,1.5,6.0, 1.5,1.5,6.0, 1.5,0.0,6.0, 0.0,0.0,3.0, 0.0,3.0,3.0, 3.0,0.0,3.0, 0.0,0.0,4.0, 0.0,4.0,4.0, 4.0,4.0,4.0, 4.0,0.0,4.0, 0.0,2.0,4.0, 2.0,4.0,4.0, 4.0,2.0,4.0, 2.0,0.0,4.0, 0.0,0.0,2.0, 0.0,4.0,2.0, 4.0,4.0,2.0, 4.0,0.0,2.0] + coords.setValues(data,56,3); + coords.setInfoOnComponent(0,"X (cm)"); + coords.setInfoOnComponent(1,"Y (cm)"); + coords.setInfoOnComponent(2,"Z (cm)"); + return coords + + def buildHexa8Mesh_1(self): + mesh=MEDCouplingUMesh.New("Hexa8Only",3); + coo=DataArrayDouble.New(); + coords=[0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.5, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 0.5, 1.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.5, 1.0, 0.5, 0.5, 1.0, 1.0, 0.5, 1.0, 0.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0] + coo.setValues(coords,27,3); + conn=[3,12,13,4,0,9,10,1, + 4,13,14,5,1,10,11,2, + 6,15,16,7,3,12,13,4, + 7,16,17,8,4,13,14,5, + 12,21,22,13,9,18,19,10, + 13,22,23,14,10,19,20,11, + 15,24,25,16,12,21,22,13, + 16,25,26,17,13,22,23,14]; + mesh.allocateCells(8); + for i in xrange(8): + mesh.insertNextCell(NORM_HEXA8,8,conn[8*i:8*(i+1)]) + pass + mesh.finishInsertingCells(); + mesh.setCoords(coo); + return mesh; + build2DTargetMesh_1=classmethod(build2DTargetMesh_1) build2DSourceMesh_1=classmethod(build2DSourceMesh_1) build3DTargetMesh_1=classmethod(build3DTargetMesh_1) @@ -446,4 +524,9 @@ class MEDCouplingDataForTest: build2DTargetMesh_4=classmethod(build2DTargetMesh_4) buildMultiFields_1=classmethod(buildMultiFields_1) buildMultiFields_2=classmethod(buildMultiFields_2) + build1DMultiTypes_1=classmethod(build1DMultiTypes_1) + build2DMultiTypes_1=classmethod(build2DMultiTypes_1) + build3DMultiTypes_1=classmethod(build3DMultiTypes_1) + buildCoordsForMultiTypes_1=classmethod(buildCoordsForMultiTypes_1) + buildHexa8Mesh_1=classmethod(buildHexa8Mesh_1) pass