From c67dc5afafbbedb547081799e1ff55dda523279b Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 24 Dec 2010 08:17:27 +0000 Subject: [PATCH] Merge from V6_2_BR 23/12/2010 --- doc/doxygen/Doxyfile_med_user.in | 2 + doc/doxygen/Makefile.am | 8 + .../Bases/InterpKernelAutoPtr.hxx | 45 ++ src/INTERP_KERNEL/Bases/Makefile.am | 3 +- .../ExprEval/InterpKernelAsmX86.cxx | 25 +- .../ExprEval/InterpKernelAsmX86.hxx | 2 +- .../ExprEval/InterpKernelExprParser.cxx | 50 +- src/MEDCoupling/MEDCouplingCMesh.cxx | 8 +- src/MEDCoupling/MEDCouplingCMesh.hxx | 2 +- src/MEDCoupling/MEDCouplingExtrudedMesh.cxx | 9 +- src/MEDCoupling/MEDCouplingExtrudedMesh.hxx | 1 + .../MEDCouplingFieldDiscretization.cxx | 6 +- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 133 +++- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 48 +- src/MEDCoupling/MEDCouplingMemArray.cxx | 506 ++++++++++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 28 +- src/MEDCoupling/MEDCouplingMesh.hxx | 2 + src/MEDCoupling/MEDCouplingPointSet.cxx | 58 +- src/MEDCoupling/MEDCouplingPointSet.hxx | 5 +- .../MEDCouplingTimeDiscretization.cxx | 253 ++++++- .../MEDCouplingTimeDiscretization.hxx | 20 + src/MEDCoupling/MEDCouplingUMesh.cxx | 263 +++++-- src/MEDCoupling/MEDCouplingUMesh.hxx | 20 +- src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 12 + src/MEDCoupling/MEDCouplingUMeshDesc.hxx | 2 + .../Test/MEDCouplingBasicsTest.hxx | 32 + .../Test/MEDCouplingBasicsTest1.cxx | 16 +- .../Test/MEDCouplingBasicsTest2.cxx | 570 ++++++++++++++- .../{libMEDCoupling_Swig.i => MEDCoupling.i} | 618 ++++++++++------ src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 557 ++++++++++++++- .../MEDCouplingDataForTest.py | 2 +- ...gRemapper_Swig.i => MEDCouplingRemapper.i} | 4 +- .../MEDCouplingRemapperTest.py | 2 +- src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 426 +++++++++-- src/MEDCoupling_Swig/Makefile.am | 34 +- src/MEDCoupling_Swig/libMEDCoupling_Swig.py | 28 + src/MEDLoader/MEDFileBasis.cxx | 48 ++ src/MEDLoader/MEDFileBasis.hxx | 61 ++ src/MEDLoader/MEDFileMesh.cxx | 666 ++++++++++++++++++ src/MEDLoader/MEDFileMesh.hxx | 124 ++++ src/MEDLoader/MEDFileMeshElt.cxx | 253 +++++++ src/MEDLoader/MEDFileMeshElt.hxx | 67 ++ src/MEDLoader/MEDFileMeshLL.cxx | 431 ++++++++++++ src/MEDLoader/MEDFileMeshLL.hxx | 112 +++ src/MEDLoader/MEDFileUtilities.cxx | 90 +++ src/MEDLoader/MEDFileUtilities.hxx | 37 + src/MEDLoader/MEDLoader.cxx | 114 ++- src/MEDLoader/MEDLoader.hxx | 2 + src/MEDLoader/Makefile.am | 7 +- .../Swig/{libMEDLoader_Swig.i => MEDLoader.i} | 50 +- src/MEDLoader/Swig/MEDLoaderDataForTest.py | 4 +- src/MEDLoader/Swig/MEDLoaderTest.py | 254 +++---- src/MEDLoader/Swig/MEDLoaderTest2.py | 2 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 92 +++ src/MEDLoader/Swig/MEDLoaderTypemaps.i | 54 ++ src/MEDLoader/Swig/Makefile.am | 23 +- .../Swig/libMEDLoader_Swig.py} | 9 +- src/MEDLoader/Test/MEDLoaderTest.cxx | 14 +- src/ParaMEDMEM/ICoCoMEDField.cxx | 2 +- src/ParaMEDMEM_Swig/Makefile.am | 28 +- .../{libParaMEDMEM_Swig.i => ParaMEDMEM.i} | 8 +- ...MEDMEM_Swig.typemap => ParaMEDMEM.typemap} | 0 src/ParaMEDMEM_Swig/test_InterpKernelDEC.py | 2 +- ...DEC.py => test_StructuredCoincidentDEC.py} | 2 +- 64 files changed, 5617 insertions(+), 739 deletions(-) create mode 100644 src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx rename src/MEDCoupling_Swig/{libMEDCoupling_Swig.i => MEDCoupling.i} (72%) rename src/MEDCoupling_Swig/{libMEDCouplingRemapper_Swig.i => MEDCouplingRemapper.i} (95%) create mode 100644 src/MEDCoupling_Swig/libMEDCoupling_Swig.py create mode 100644 src/MEDLoader/MEDFileBasis.cxx create mode 100644 src/MEDLoader/MEDFileBasis.hxx create mode 100644 src/MEDLoader/MEDFileMesh.cxx create mode 100644 src/MEDLoader/MEDFileMesh.hxx create mode 100644 src/MEDLoader/MEDFileMeshElt.cxx create mode 100644 src/MEDLoader/MEDFileMeshElt.hxx create mode 100644 src/MEDLoader/MEDFileMeshLL.cxx create mode 100644 src/MEDLoader/MEDFileMeshLL.hxx create mode 100644 src/MEDLoader/MEDFileUtilities.cxx create mode 100644 src/MEDLoader/MEDFileUtilities.hxx rename src/MEDLoader/Swig/{libMEDLoader_Swig.i => MEDLoader.i} (82%) create mode 100644 src/MEDLoader/Swig/MEDLoaderTest3.py rename src/{ParaMEDMEM_Swig/ParaMEDMEM.py => MEDLoader/Swig/libMEDLoader_Swig.py} (67%) rename src/ParaMEDMEM_Swig/{libParaMEDMEM_Swig.i => ParaMEDMEM.i} (98%) rename src/ParaMEDMEM_Swig/{libParaMEDMEM_Swig.typemap => ParaMEDMEM.typemap} (100%) rename src/ParaMEDMEM_Swig/{test_StructuredCoincodentDEC.py => test_StructuredCoincidentDEC.py} (99%) diff --git a/doc/doxygen/Doxyfile_med_user.in b/doc/doxygen/Doxyfile_med_user.in index ef07e414c..01b76df5c 100644 --- a/doc/doxygen/Doxyfile_med_user.in +++ b/doc/doxygen/Doxyfile_med_user.in @@ -71,6 +71,7 @@ WARN_LOGFILE = log_user INPUT = @srcdir@ \ @srcdir@/../../src/ParaMEDMEM \ @srcdir@/../../src/INTERP_KERNEL \ + @srcdir@/../../src/INTERP_KERNEL/Bases \ @srcdir@/../../src/INTERP_KERNEL/Geometric2D \ @srcdir@/../../src/MEDCoupling \ @srcdir@/../../src/MEDLoader \ @@ -89,6 +90,7 @@ FILE_PATTERNS = MEDMEM_Mesh.* \ ExplicitCoincidentDEC.* \ NonCoincidentDEC.* \ CommInterface.* \ + NormalizedUnstructuredMesh.* \ Interpolation2D.* \ Interpolation3D.* \ Interpolation3DSurf.* \ diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am index 178b3c688..b49523f5f 100644 --- a/doc/doxygen/Makefile.am +++ b/doc/doxygen/Makefile.am @@ -43,10 +43,18 @@ clean-local: EXTRA_DIST += figures \ main.dox \ + Geometric2D.dox \ MED_class.dox \ biblio.dox \ + barycoords.dox \ + dualmesh.dox \ + extractor.dox \ field.dox \ grid.dox \ + interpkernel.dox \ + medcoupling.dox \ + medloader.dox \ + medmem.dox \ medsplitter.dox \ mesh.dox \ meshing.dox \ diff --git a/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx new file mode 100644 index 000000000..5851a249f --- /dev/null +++ b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __INTERPKERNELAUTOPTR_HXX__ +#define __INTERPKERNELAUTOPTR_HXX__ + +namespace INTERP_KERNEL +{ + template + class AutoPtr + { + public: + AutoPtr(T *ptr=0):_ptr(ptr) { } + ~AutoPtr() { destroyPtr(); } + AutoPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; } + T *operator->() { return _ptr ; } + const T *operator->() const { return _ptr; } + T& operator*() { return *_ptr; } + const T& operator*() const { return *_ptr; } + operator T *() { return _ptr; } + operator const T *() const { return _ptr; } + private: + void destroyPtr() { delete [] _ptr; } + private: + T *_ptr; + }; +} + +#endif diff --git a/src/INTERP_KERNEL/Bases/Makefile.am b/src/INTERP_KERNEL/Bases/Makefile.am index fc89569bc..4b74948f3 100755 --- a/src/INTERP_KERNEL/Bases/Makefile.am +++ b/src/INTERP_KERNEL/Bases/Makefile.am @@ -32,7 +32,8 @@ NormalizedUnstructuredMesh.hxx \ InterpKernelStlExt.hxx \ InterpKernelHashMap.hxx \ InterpKernelHashTable.hxx \ -InterpKernelHashFun.hxx +InterpKernelHashFun.hxx \ +InterpKernelAutoPtr.hxx # Libraries targets diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx index ee7116fd2..479b5c78e 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx @@ -23,6 +23,14 @@ #include #include +#ifdef _POSIX_MAPPED_FILES +#include +#else +#ifdef WNT +#include +#endif +#endif + const char *INTERP_KERNEL::AsmX86::OPS[NB_OF_OPS]={"mov","push","pop","fld","faddp","fsubp","fmulp","fdivp","fcos","fsin","fabs","fchs","fsqrt","sub","add","ret","leave","movsd","fst"}; std::vector INTERP_KERNEL::AsmX86::convertIntoMachineLangage(const std::vector& asmb) const throw(INTERP_KERNEL::Exception) @@ -33,11 +41,20 @@ std::vector INTERP_KERNEL::AsmX86::convertIntoMachineLangage(const std::ve return ret; } -char *INTERP_KERNEL::AsmX86::convertMachineLangageInBasic(const std::vector& ml, int& lgth) const +char *INTERP_KERNEL::AsmX86::copyToExecMemZone(const std::vector& ml, unsigned& offset) const { - lgth=ml.size(); - char *ret=new char[lgth]; - std::copy(ml.begin(),ml.end(),ret); + char *ret=0; + int lgth=ml.size(); +#ifdef _POSIX_MAPPED_FILES + ret=(char *)mmap(0,lgth,PROT_EXEC | PROT_WRITE,MAP_ANONYMOUS | MAP_PRIVATE,-1,0); +#else +#ifdef WNT + HANDLE h=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_EXECUTE_READWRITE,0,lgth,NULL); + ret=(char *)MapViewOfFile(h,FILE_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE,0,0,lgth); +#endif +#endif + if(ret) + std::copy(ml.begin(),ml.end(),ret); return ret; } diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.hxx b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.hxx index 11b8733e5..fd7bc9afc 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.hxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.hxx @@ -32,7 +32,7 @@ namespace INTERP_KERNEL { public: std::vector convertIntoMachineLangage(const std::vector& asmb) const throw(INTERP_KERNEL::Exception); - char *convertMachineLangageInBasic(const std::vector& ml, int& lgth) const; + char *copyToExecMemZone(const std::vector& ml, unsigned& offset) const; private: void convertOneInstructionInML(const std::string& inst, std::vector& ml) const throw(INTERP_KERNEL::Exception); private: diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx index 585fac2f8..1f6b497b5 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx @@ -28,14 +28,6 @@ #include #include -#ifdef _POSIX_MAPPED_FILES -#include -#else -#ifdef WNT -#include -#endif -#endif - using namespace INTERP_KERNEL; const char LeafExprVar::END_OF_RECOGNIZED_VAR[]="Vec"; @@ -719,21 +711,8 @@ char *ExprParser::compileX86() const for(std::vector::const_iterator iter=output.begin();iter!=output.end();iter++) std::cout << std::hex << (int)((unsigned char)(*iter)) << " "; std::cout << std::endl; - int lgth; - char *lm=asmb.convertMachineLangageInBasic(output,lgth); - char *ret=0; -#ifdef _POSIX_MAPPED_FILES - ret=(char *)mmap(0,lgth,PROT_EXEC | PROT_WRITE,MAP_ANONYMOUS | MAP_PRIVATE,-1,0); -#else -#ifdef WNT - HANDLE h=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_EXECUTE_READWRITE,0,lgth,NULL); - ret=(char *)MapViewOfFile(h,FILE_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE,0,0,lgth); -#endif -#endif - if(ret) - std::copy(lm,lm+lgth,ret); - delete [] lm; - return ret; + unsigned offset; + return asmb.copyToExecMemZone(output,offset); } char *ExprParser::compileX86_64() const @@ -757,21 +736,8 @@ char *ExprParser::compileX86_64() const for(std::vector::const_iterator iter=output.begin();iter!=output.end();iter++) std::cout << std::hex << (int)((unsigned char)(*iter)) << " "; std::cout << std::endl; - int lgth; - char *lm=asmb.convertMachineLangageInBasic(output,lgth); - char *ret=0; -#ifdef _POSIX_MAPPED_FILES - ret=(char *)mmap(0,lgth,PROT_EXEC | PROT_WRITE,MAP_ANONYMOUS | MAP_PRIVATE,-1,0); -#else -#ifdef WNT - HANDLE h=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_EXECUTE_READWRITE,0,lgth,NULL); - ret=(char *)MapViewOfFile(h,FILE_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE,0,0,lgth); -#endif -#endif - if(ret) - std::copy(lm,lm+lgth,ret); - delete [] lm; - return ret; + unsigned offset; + return asmb.copyToExecMemZone(output,offset); } void ExprParser::compileX86LowLev(std::vector& ass) const @@ -782,9 +748,9 @@ void ExprParser::compileX86LowLev(std::vector& ass) const { for(std::list::const_iterator iter=_sub_expr.begin();iter!=_sub_expr.end();iter++) (*iter).compileX86LowLev(ass); - for(std::list::const_iterator iter2=_func_btw_sub_expr.begin();iter2!=_func_btw_sub_expr.end();iter2++) - (*iter2)->operateX86(ass); } + for(std::list::const_iterator iter2=_func_btw_sub_expr.begin();iter2!=_func_btw_sub_expr.end();iter2++) + (*iter2)->operateX86(ass); } void ExprParser::compileX86_64LowLev(std::vector& ass) const @@ -795,9 +761,9 @@ void ExprParser::compileX86_64LowLev(std::vector& ass) const { for(std::list::const_iterator iter=_sub_expr.begin();iter!=_sub_expr.end();iter++) (*iter).compileX86_64LowLev(ass); - for(std::list::const_iterator iter2=_func_btw_sub_expr.begin();iter2!=_func_btw_sub_expr.end();iter2++) - (*iter2)->operateX86(ass); } + for(std::list::const_iterator iter2=_func_btw_sub_expr.begin();iter2!=_func_btw_sub_expr.end();iter2++) + (*iter2)->operateX86(ass); } void LeafExprVal::compileX86(std::vector& ass) const diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 4c49d3b93..9ec8bec95 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -37,11 +37,11 @@ MEDCouplingCMesh::MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCpy): if(deepCpy) { if(other._x_array) - _x_array=_x_array->deepCopy(); + _x_array=_x_array->deepCpy(); if(other._y_array) - _y_array=_y_array->deepCopy(); + _y_array=_y_array->deepCpy(); if(other._z_array) - _z_array=_z_array->deepCopy(); + _z_array=_z_array->deepCpy(); } else { @@ -436,7 +436,7 @@ void MEDCouplingCMesh::setCoords(DataArrayDouble *coordsX, DataArrayDouble *coor declareAsNew(); } -MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const +MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) { int spaceDim=getSpaceDimension(); MEDCouplingUMesh *ret=MEDCouplingUMesh::New(getName(),spaceDim); diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index c7d9e8792..3d047a6eb 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -63,7 +63,7 @@ namespace ParaMEDMEM DataArrayDouble *coordsY=0, DataArrayDouble *coordsZ=0); // tools - MEDCouplingUMesh *buildUnstructured() const; + MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 84a9d451c..d386e340e 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -104,7 +104,7 @@ MEDCouplingExtrudedMesh::MEDCouplingExtrudedMesh(const MEDCouplingExtrudedMesh& { _mesh2D=other._mesh2D->clone(true); _mesh1D=other._mesh1D->clone(true); - _mesh3D_ids=other._mesh3D_ids->deepCopy(); + _mesh3D_ids=other._mesh3D_ids->deepCpy(); } else { @@ -323,13 +323,18 @@ void MEDCouplingExtrudedMesh::renumberCells(const int *old2NewBg, bool check) th MEDCouplingUMesh *MEDCouplingExtrudedMesh::build3DUnstructuredMesh() const { - MEDCouplingUMesh *ret=_mesh2D->buildExtrudedMeshFromThis(_mesh1D,0); + MEDCouplingUMesh *ret=_mesh2D->buildExtrudedMesh(_mesh1D,0); const int *renum=_mesh3D_ids->getConstPointer(); ret->renumberCells(renum,false); ret->setName(getName()); return ret; } +MEDCouplingUMesh *MEDCouplingExtrudedMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) +{ + return build3DUnstructuredMesh(); +} + MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::getMeasureField(bool) const { std::string name="MeasureOfMesh_"; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 363172410..d5025341e 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM MEDCouplingUMesh *getMesh1D() const { return _mesh1D; } DataArrayInt *getMesh3DIds() const { return _mesh3D_ids; } MEDCouplingUMesh *build3DUnstructuredMesh() const; + MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getMeasureField(bool) const; MEDCouplingFieldDouble *getMeasureFieldOnNode(bool) const; MEDCouplingFieldDouble *buildOrthogonalField() const; diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index e5ad06173..d5c1a1e8c 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -259,7 +259,7 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(const int *old2N int oldNbOfElems=arr->getNumberOfTuples(); int nbOfComp=arr->getNumberOfComponents(); int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1; - DataArrayDouble *arrCpy=arr->deepCopy(); + DataArrayDouble *arrCpy=arr->deepCpy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(newNbOfTuples); double *ptToFill=arr->getPointer(); @@ -291,7 +291,7 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(const int *old2N void MEDCouplingFieldDiscretization::renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) { int nbOfComp=arr->getNumberOfComponents(); - DataArrayDouble *arrCpy=arr->deepCopy(); + DataArrayDouble *arrCpy=arr->deepCpy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(new2OldSz); double *ptToFill=arr->getPointer(); @@ -586,7 +586,7 @@ MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(con { DataArrayInt *arr=other._discr_per_cell; if(arr) - _discr_per_cell=arr->deepCopy(); + _discr_per_cell=arr->deepCpy(); } void MEDCouplingFieldDiscretizationPerCell::updateTime() diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 60b5caab8..d24f36c12 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -52,6 +52,11 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) c return ret; } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const +{ + return cloneWithMesh(true); +} + MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const { MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(_time_discr,td,deepCpy); @@ -221,6 +226,39 @@ bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) return true; } +/*! + * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that + * number of components between 'this' and 'other' can be different here (for operator/). + */ +bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const +{ + if(!MEDCouplingField::areStrictlyCompatible(other)) + return false; + const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + if(!otherC) + return false; + if(_nature!=otherC->_nature) + return false; + if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) + return false; + return true; +} + +/*! + * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible, + * except that 'this' and other can have different number of components. + */ +bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble *other) const +{ + if(!MEDCouplingField::areStrictlyCompatible(other)) + return false; + if(_nature!=other->_nature) + return false; + if(!_time_discr->areCompatibleForMeld(other->_time_discr)) + return false; + return true; +} + /*! * This method performs a clone of mesh and a renumbering of underlying cells of it. The number of cells remains the same. * The values of field are impacted in consequence to have the same geometrical field. @@ -1033,6 +1071,29 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps) throw(INTERP_KERNEL::Excepti return true; } +/*! + * Merge nodes with (barycenter computation) of underlying mesh. In case of some node will be merged the underlying mesh instance will change. + */ +bool MEDCouplingFieldDouble::mergeNodes2(double eps) throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); + if(!meshC) + throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !"); + MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); + bool ret; + int ret2; + MEDCouplingAutoRefCountObjectPtr arr=meshC2->mergeNodes2(eps,ret,ret2); + if(!ret)//no nodes have been merged. + return ret; + std::vector arrays; + _time_discr->getArrays(arrays); + for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();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. @@ -1221,7 +1282,7 @@ void MEDCouplingFieldDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Excepti _time_discr->sortPerTuple(asc); } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areCompatibleForMerge(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply mergeFields on them !"); @@ -1229,6 +1290,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFie const MEDCouplingMesh *m2=f2->getMesh(); MEDCouplingMesh *m=m1->mergeMyselfWith(m2); MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); + td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(m); m->decrRef(); @@ -1237,7 +1299,48 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const MEDCouplingFie return ret; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::mergeFields(const std::vector& a) throw(INTERP_KERNEL::Exception) +{ + if(a.size()<=1) + throw INTERP_KERNEL::Exception("FieldDouble::mergeFields : size of array must be > 1 !"); + std::vector< MEDCouplingAutoRefCountObjectPtr > ms(a.size()); + std::vector< const MEDCouplingUMesh *> ms2(a.size()); + std::vector< const MEDCouplingTimeDiscretization *> tds(a.size()); + std::vector::const_iterator it=a.begin(); + const MEDCouplingFieldDouble *ref=(*it++); + for(;it!=a.end();it++) + if(!ref->areCompatibleForMerge(*it)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply mergeFields on them !"); + for(int i=0;i<(int)a.size();i++) + { + if(!a[i]->getMesh()) + throw INTERP_KERNEL::Exception("mergeFields : A field as no underlying mesh !"); + ms[i]=a[i]->getMesh()->buildUnstructured(); + ms2[i]=ms[i]; + tds[i]=a[i]->_time_discr; + } + MEDCouplingAutoRefCountObjectPtr m=MEDCouplingUMesh::mergeUMeshes(ms2); + MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds); + td->copyTinyAttrFrom(*(a[0]->_time_discr)); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); + ret->setMesh(m); + ret->setName(a[0]->getName()); + ret->setDescription(a[0]->getDescription()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::meldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) +{ + if(!f1->areCompatibleForMeld(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply meldFields on them !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr); + td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + ret->setMesh(f1->getMesh()); + return ret; +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply dotFields on them !"); @@ -1248,7 +1351,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::dotFields(const MEDCouplingField return ret; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply crossProductFields on them !"); @@ -1259,7 +1362,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::crossProductFields(const MEDCoup return ret; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply maxFields on them !"); @@ -1270,7 +1373,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxFields(const MEDCouplingField return ret; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply minFields on them !"); @@ -1281,7 +1384,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::minFields(const MEDCouplingField return ret; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply addFields on them !"); @@ -1292,7 +1395,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::addFields(const MEDCouplingField return ret; } -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { if(!areStrictlyCompatible(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !"); @@ -1300,7 +1403,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCoupli return *this; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply substractFields on them !"); @@ -1311,7 +1414,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::substractFields(const MEDCouplin return ret; } -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { if(!areStrictlyCompatible(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !"); @@ -1319,7 +1422,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCoupli return *this; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1->areCompatibleForMul(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply multiplyFields on them !"); @@ -1330,7 +1433,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCoupling return ret; } -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { if(!areCompatibleForMul(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !"); @@ -1338,9 +1441,9 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli return *this; } -MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { - if(!f1->areStrictlyCompatible(f2)) + if(!f1->areCompatibleForDiv(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply divideFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); @@ -1349,9 +1452,9 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFi return ret; } -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { - if(!areStrictlyCompatible(&other)) + if(!areCompatibleForDiv(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !"); _time_discr->divideEqual(other._time_discr); return *this; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 19f804c31..719bc41c8 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -41,6 +41,8 @@ namespace ParaMEDMEM bool areCompatibleForMerge(const MEDCouplingField *other) const; bool areStrictlyCompatible(const MEDCouplingField *other) const; bool areCompatibleForMul(const MEDCouplingField *other) const; + bool areCompatibleForDiv(const MEDCouplingField *other) const; + bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const; void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); void renumberCellsWithoutMesh(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); void renumberNodes(const int *old2NewBg) throw(INTERP_KERNEL::Exception); @@ -48,6 +50,7 @@ namespace ParaMEDMEM DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *deepCpy() const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const; @@ -112,6 +115,7 @@ 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 mergeNodes2(double eps) throw(INTERP_KERNEL::Exception); bool zipCoords() throw(INTERP_KERNEL::Exception); bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception); bool simplexize(int policy) throw(INTERP_KERNEL::Exception); @@ -128,27 +132,29 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); - static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const { return dotFields(this,&other); } - static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const { return crossProductFields(this,&other); } - static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const { return maxFields(this,&other); } - static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const { return minFields(this,&other); } - MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); } - const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other); - static MEDCouplingFieldDouble *addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const { return substractFields(this,&other); } - const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other); - static MEDCouplingFieldDouble *substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const { return multiplyFields(this,&other); } - const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other); - static MEDCouplingFieldDouble *multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const { return divideFields(this,&other); } - const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other); - static MEDCouplingFieldDouble *divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *mergeFields(const std::vector& a) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *meldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return dotFields(this,&other); } + static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return crossProductFields(this,&other); } + static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return maxFields(this,&other); } + static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return minFields(this,&other); } + MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return addFields(this,&other); } + const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *addFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return substractFields(this,&other); } + const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *substractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return multiplyFields(this,&other); } + const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return divideFields(this,&other); } + const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 1b4a20b49..d0596e339 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -131,15 +131,15 @@ void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception) throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !"); } -DataArrayDouble *DataArrayDouble::deepCopy() const +DataArrayDouble *DataArrayDouble::deepCpy() const { return new DataArrayDouble(*this); } -DataArrayDouble *DataArrayDouble::performCpy(bool deepCpy) const +DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const { - if(deepCpy) - return deepCopy(); + if(dCpy) + return deepCpy(); else { incrRef(); @@ -403,6 +403,29 @@ DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const in return ret; } +/*! + * This method is equivalent to DataArrayInt::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption ! + */ +DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + int nbComp=getNumberOfComponents(); + int oldNbOfTuples=getNumberOfTuples(); + 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++) + if(*w>=0 && *wgetNumberOfTuples) !"); + ret->copyStringInfoFrom(*this); + ret->incrRef(); + return ret; +} + /*! * This methods has a similar behaviour than std::string::substr. This method returns a newly created DataArrayInt that is part of this with same number of components. * The intervall is specified by [tupleIdBg,tupleIdEnd) except if tupleIdEnd ==-1 in this case the [tupleIdBg,this->end()) will be kept. @@ -461,6 +484,25 @@ DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double d return ret; } +/*! + * Contrary to DataArrayDouble::changeNbOfComponents method this method is \b not const. The content + * This method \b do \b not change the content of data but changes the splitting of this data seen by the caller. + * This method makes the assumption that 'this' is already allocated. If not an exception will be thrown. + * This method checks that getNbOfElems()%newNbOfCompo==0. If not an exception will be throw ! + * This method erases all components info set before call ! + */ +void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfElems=getNbOfElems(); + if(nbOfElems%newNbOfCompo!=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !"); + _nb_of_tuples=nbOfElems/newNbOfCompo; + _info_on_compo.clear(); + _info_on_compo.resize(newNbOfCompo); + declareAsNew(); +} + DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) { checkAllocated(); @@ -479,6 +521,37 @@ DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector& return ret; } +/*! + * This method melds the components of 'this' with components of 'other'. + * After this call in case of success, 'this' will contain a number of components equal to the sum of 'this' + * before the call and the number of components of 'other'. + * This method expects that 'this' and 'other' have exactly the same number of tuples. If not an exception is thrown. + */ +void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + other->checkAllocated(); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples!=other->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !"); + int nbOfComp1=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + double *newArr=new double[nbOfTuples*(nbOfComp1+nbOfComp2)]; + double *w=newArr; + const double *inp1=getConstPointer(); + const double *inp2=other->getConstPointer(); + for(int i=0;i compIds(nbOfComp2); + for(int i=0;i& compoIds) throw(INTERP_KERNEL::Exception) { copyPartOfStringInfoFrom2(compoIds,*a); @@ -1035,16 +1108,74 @@ DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const thr DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { - int nbOfComp=a1->getNumberOfComponents(); - if(nbOfComp!=a2->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array aggregation !"); - int nbOfTuple1=a1->getNumberOfTuples(); - int nbOfTuple2=a2->getNumberOfTuples(); + std::vector tmp(2); + tmp[0]=a1; tmp[1]=a2; + return aggregate(tmp); +} + +DataArrayDouble *DataArrayDouble::aggregate(const std::vector& a) throw(INTERP_KERNEL::Exception) +{ + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : input list must be NON EMPTY !"); + std::vector::const_iterator it=a.begin(); + int nbOfComp=(*it)->getNumberOfComponents(); + int nbt=(*it++)->getNumberOfTuples(); + for(int i=1;it!=a.end();it++,i++) + { + if((*it)->getNumberOfComponents()!=nbOfComp) + throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : Nb of components mismatch for array aggregation !"); + nbt+=(*it)->getNumberOfTuples(); + } DataArrayDouble *ret=DataArrayDouble::New(); - ret->alloc(nbOfTuple1+nbOfTuple2,nbOfComp); - double *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer()); - std::copy(a2->getConstPointer(),a2->getConstPointer()+nbOfTuple2*nbOfComp,pt); - ret->copyStringInfoFrom(*a1); + ret->alloc(nbt,nbOfComp); + double *pt=ret->getPointer(); + for(it=a.begin();it!=a.end();it++) + pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt); + ret->copyStringInfoFrom(*(a[0])); + return ret; +} + +DataArrayDouble *DataArrayDouble::meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) +{ + std::vector arr(2); + arr[0]=a1; arr[1]=a2; + return meld(arr); +} + +DataArrayDouble *DataArrayDouble::meld(const std::vector& a) throw(INTERP_KERNEL::Exception) +{ + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayDouble::meld : array must be NON empty !"); + std::vector::const_iterator it; + for(it=a.begin();it!=a.end();it++) + (*it)->checkAllocated(); + it=a.begin(); + int nbOfTuples=(*it)->getNumberOfTuples(); + std::vector nbc(a.size()); + std::vector pts(a.size()); + nbc[0]=(*it)->getNumberOfComponents(); + pts[0]=(*it++)->getConstPointer(); + for(int i=1;it!=a.end();it++,i++) + { + if(nbOfTuples!=(*it)->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayDouble::meld : mismatch of number of tuples !"); + nbc[i]=(*it)->getNumberOfComponents(); + pts[i]=(*it)->getConstPointer(); + } + int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); + DataArrayDouble *ret=DataArrayDouble::New(); + ret->alloc(nbOfTuples,totalNbOfComp); + double *retPtr=ret->getPointer(); + for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); return ret; } @@ -1270,28 +1401,63 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { - int nbOfComp=a1->getNumberOfComponents(); - if(nbOfComp!=a2->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !"); int nbOfTuple=a1->getNumberOfTuples(); - if(nbOfTuple!=a2->getNumberOfTuples()) + int nbOfTuple2=a2->getNumberOfTuples(); + int nbOfComp=a1->getNumberOfComponents(); + int nbOfComp2=a2->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divide !"); - DataArrayDouble *ret=DataArrayDouble::New(); - ret->alloc(nbOfTuple,nbOfComp); - std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides()); - ret->copyStringInfoFrom(*a1); + DataArrayDouble *ret=0; + if(nbOfComp==nbOfComp2) + { + ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides()); + ret->copyStringInfoFrom(*a1); + } + else + { + if(nbOfComp2==1) + { + ret=DataArrayDouble::New(); + ret->alloc(nbOfTuple,nbOfComp); + const double *a2Ptr=a2->getConstPointer(); + const double *a1Ptr=a1->getConstPointer(); + double *res=ret->getPointer(); + for(int i=0;i(),a2Ptr[i])); + ret->copyStringInfoFrom(*a1); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !"); + } return ret; } void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { - int nbOfComp=getNumberOfComponents(); - if(nbOfComp!=other->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !"); int nbOfTuple=getNumberOfTuples(); - if(nbOfTuple!=other->getNumberOfTuples()) + int nbOfTuple2=other->getNumberOfTuples(); + int nbOfComp=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divideEqual !"); - std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides()); + if(nbOfComp==nbOfComp2) + { + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides()); + } + else + { + if(nbOfComp2==1) + { + const double *ptr=other->getConstPointer(); + double *myPtr=getPointer(); + for(int i=0;i(),ptr[i])); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !"); + } declareAsNew(); } @@ -1311,15 +1477,15 @@ void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception) throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !"); } -DataArrayInt *DataArrayInt::deepCopy() const +DataArrayInt *DataArrayInt::deepCpy() const { return new DataArrayInt(*this); } -DataArrayInt *DataArrayInt::performCpy(bool deepCpy) const +DataArrayInt *DataArrayInt::performCpy(bool dCpy) const { - if(deepCpy) - return deepCopy(); + if(dCpy) + return deepCpy(); else { incrRef(); @@ -1579,6 +1745,29 @@ DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new return ret; } +/*! + * This method is equivalent to DataArrayInt::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption ! + */ +DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + int nbComp=getNumberOfComponents(); + int oldNbOfTuples=getNumberOfTuples(); + 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++) + if(*w>=0 && *wgetNumberOfTuples) !"); + ret->copyStringInfoFrom(*this); + ret->incrRef(); + return ret; +} + /*! * This method checks that 'this' is with numberofcomponents == 1 and that it is equal to * stdext::iota() of size getNumberOfTuples. This method is particalary usefull for DataArrayInt instances @@ -1649,6 +1838,25 @@ DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(IN return ret; } +/*! + * Contrary to DataArrayInt::changeNbOfComponents method this method is \b not const. The content + * This method \b do \b not change the content of data but changes the splitting of this data seen by the caller. + * This method makes the assumption that 'this' is already allocated. If not an exception will be thrown. + * This method checks that getNbOfElems()%newNbOfCompo==0. If not an exception will be throw ! + * This method erases all components info set before call ! + */ +void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfElems=getNbOfElems(); + if(nbOfElems%newNbOfCompo!=0) + throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !"); + _nb_of_tuples=nbOfElems/newNbOfCompo; + _info_on_compo.clear(); + _info_on_compo.resize(newNbOfCompo); + declareAsNew(); +} + /*! * This method builds a new instance of DataArrayInt (to deal with) that is reduction or an extension of 'this'. * if 'newNbOfComp' < this->getNumberOfComponents() a reduction is done and for each tuple 'newNbOfComp' first components are kept. @@ -1705,6 +1913,37 @@ DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector& compo return ret; } +/*! + * This method melds the components of 'this' with components of 'other'. + * After this call in case of success, 'this' will contain a number of components equal to the sum of 'this' + * before the call and the number of components of 'other'. + * This method expects that 'this' and 'other' have exactly the same number of tuples. If not an exception is thrown. + */ +void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + other->checkAllocated(); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples!=other->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !"); + int nbOfComp1=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + int *newArr=new int[nbOfTuples*(nbOfComp1+nbOfComp2)]; + int *w=newArr; + const int *inp1=getConstPointer(); + const int *inp2=other->getConstPointer(); + for(int i=0;i compIds(nbOfComp2); + for(int i=0;i& compoIds) throw(INTERP_KERNEL::Exception) { copyPartOfStringInfoFrom2(compoIds,*a); @@ -1778,6 +2017,76 @@ DataArrayInt *DataArrayInt::aggregate(const DataArrayInt *a1, const DataArrayInt return ret; } +int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !"); + const int *vals=getConstPointer(); + const int *loc=std::max_element(vals,vals+nbOfTuples); + tupleId=std::distance(vals,loc); + return *loc; +} + +int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !"); + const int *vals=getConstPointer(); + const int *loc=std::min_element(vals,vals+nbOfTuples); + tupleId=std::distance(vals,loc); + return *loc; +} + +DataArrayInt *DataArrayInt::meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + std::vector arr(2); + arr[0]=a1; arr[1]=a2; + return meld(arr); +} + +DataArrayInt *DataArrayInt::meld(const std::vector& a) throw(INTERP_KERNEL::Exception) +{ + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayInt::meld : array must be NON empty !"); + std::vector::const_iterator it; + for(it=a.begin();it!=a.end();it++) + (*it)->checkAllocated(); + it=a.begin(); + int nbOfTuples=(*it)->getNumberOfTuples(); + std::vector nbc(a.size()); + std::vector pts(a.size()); + nbc[0]=(*it)->getNumberOfComponents(); + pts[0]=(*it++)->getConstPointer(); + for(int i=1;it!=a.end();it++,i++) + { + if(nbOfTuples!=(*it)->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !"); + nbc[i]=(*it)->getNumberOfComponents(); + pts[i]=(*it)->getConstPointer(); + } + int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples,totalNbOfComp); + int *retPtr=ret->getPointer(); + for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + return ret; +} + /*! * This method create a minimal partition of groups 'groups' the std::iota array of size 'newNb'. * This method returns an array of size 'newNb' that specifies for each item at which familyId it owns to, and this method returns @@ -1829,6 +2138,143 @@ DataArrayInt *DataArrayInt::makePartition(const std::vector& gro return ret; } +DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : only single component allowed !"); + std::vector tmp(nbOfElement); + const int *pt=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + for(const int *w=pt;w!=pt+nbOfTuples;w++) + if(*w>=0 && *walloc(nbOfRetVal,1); + int j=0; + int *retPtr=ret->getPointer(); + for(int i=0;icheckAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !"); + if(other->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !"); + const int *pt=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + std::set s1(pt,pt+nbOfTuples); + pt=other->getConstPointer(); + nbOfTuples=other->getNumberOfTuples(); + std::set s2(pt,pt+nbOfTuples); + std::vector r; + std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector >(r)); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(r.size(),1); + std::copy(r.begin(),r.end(),ret->getPointer()); + return ret; +} + +DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + other->checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildUnion : only single component allowed !"); + if(other->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildUnion : only single component allowed for other type !"); + int tmp1; + int valm=getMinValue(tmp1); + valm=std::min(other->getMinValue(tmp1),valm); + if(valm<0) + throw INTERP_KERNEL::Exception("DataArrayInt::buildUnion : a negative value has been detected !"); + // + const int *pt=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + std::set s1(pt,pt+nbOfTuples); + pt=other->getConstPointer(); + nbOfTuples=other->getNumberOfTuples(); + std::set s2(pt,pt+nbOfTuples); + std::vector r; + std::set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector >(r)); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(r.size(),1); + std::copy(r.begin(),r.end(),ret->getPointer()); + return ret; +} + +DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + other->checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildIntersection : only single component allowed !"); + if(other->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildIntersection : only single component allowed for other type !"); + int tmp1; + int valm=getMinValue(tmp1); + valm=std::min(other->getMinValue(tmp1),valm); + if(valm<0) + throw INTERP_KERNEL::Exception("DataArrayInt::buildIntersection : a negative value has been detected !"); + // + const int *pt=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + std::set s1(pt,pt+nbOfTuples); + pt=other->getConstPointer(); + nbOfTuples=other->getNumberOfTuples(); + std::set s2(pt,pt+nbOfTuples); + std::vector r; + std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector >(r)); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(r.size(),1); + std::copy(r.begin(),r.end(),ret->getPointer()); + return ret; +} + +/*! + * This method could be usefull for returned DataArrayInt marked as index. Some methods that generate such DataArrayInt instances: + * - ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity + * - ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex + * This method makes the assumption that 'this' is allocated and has exactly one component and 2 or more tuples. If not an exception is thrown. + * This method retrives a newly created DataArrayInt instance with 1 component and this->getNumberOfTuples()-1 tuples. + * If this contains [1,3,6,7,7,9,15] -> returned array will contain [2,3,1,0,2,6]. + */ +DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<2) + throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !"); + const int *ptr=getPointer(); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples-1,1); + int *out=ret->getPointer(); + std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus()); + return ret; +} + +/*! + * This method returns all different values found in 'this'. + */ +std::set DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + std::set ret; + ret.insert(getConstPointer(),getConstPointer()+getNbOfElems()); + return ret; +} + int *DataArrayInt::checkAndPreparePermutation(const int *start, const int *end) { int sz=std::distance(start,end); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 57d7d8a0a..c3259e03b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -25,6 +25,7 @@ #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" +#include #include #include #include @@ -118,7 +119,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayDouble *New(); MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayDouble *deepCopy() const; + MEDCOUPLING_EXPORT DataArrayDouble *deepCpy() const; MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const; MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); @@ -144,13 +145,17 @@ namespace ParaMEDMEM 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 *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); } + MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } MEDCOUPLING_EXPORT double *getPointer() const { return _mem.getPointer(); } MEDCOUPLING_EXPORT static void setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet); MEDCOUPLING_EXPORT const double *getConstPointer() const { return _mem.getConstPointer(); } @@ -185,6 +190,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const std::vector& a) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *meld(const std::vector& a) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *crossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayDouble *max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); @@ -211,7 +219,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayInt *New(); MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayInt *deepCopy() const; + MEDCOUPLING_EXPORT DataArrayInt *deepCpy() const; MEDCOUPLING_EXPORT DataArrayInt *performCpy(bool deepCpy) const; MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const; @@ -239,22 +247,36 @@ namespace ParaMEDMEM 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 DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isIdentity() const; MEDCOUPLING_EXPORT bool isUniform(int val) const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } - MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } + MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); } + MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } MEDCOUPLING_EXPORT int *getPointer() const { return _mem.getPointer(); } MEDCOUPLING_EXPORT static void setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet); MEDCOUPLING_EXPORT const int *getConstPointer() const { return _mem.getConstPointer(); } MEDCOUPLING_EXPORT DataArrayInt *getIdsEqual(int val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2); + MEDCOUPLING_EXPORT static DataArrayInt *meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayInt *meld(const std::vector& a) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *makePartition(const std::vector& groups, int newNb, std::vector< std::vector >& fidsOfGroups); + MEDCOUPLING_EXPORT DataArrayInt *buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::set getDifferentValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } //! nothing to do here because this class does not aggregate any TimeLabel instance. diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 75ed3f309..d5b828676 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -40,6 +40,7 @@ namespace ParaMEDMEM class DataArrayInt; class DataArrayDouble; + class MEDCouplingUMesh; class MEDCouplingFieldDouble; class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject, public TimeLabel @@ -91,6 +92,7 @@ namespace ParaMEDMEM virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const = 0; virtual MEDCouplingMesh *buildPart(const int *start, const int *end) const = 0; virtual MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const = 0; + virtual MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception) = 0; virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const; static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index e587b2978..d4812d83a 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -326,6 +326,38 @@ void MEDCouplingPointSet::renumberNodes(const int *newNodeNumbers, int newNbOfNo newCoords->decrRef(); } +/* + * This method renumber 'this' using 'newNodeNumbers' array of size this->getNumberOfNodes. + * newNbOfNodes specifies the *std::max_element(newNodeNumbers,newNodeNumbers+this->getNumberOfNodes()) + * This value is asked because often known by the caller of this method. + * Contrary to ParaMEDMEM::MEDCouplingPointSet::renumberNodes method for merged nodes the barycenter of them is computed here. + * + * @param newNodeNumbers array specifying the new numbering. + * @param newNbOfNodes the new number of nodes. + */ +void MEDCouplingPointSet::renumberNodes2(const int *newNodeNumbers, int newNbOfNodes) +{ + DataArrayDouble *newCoords=DataArrayDouble::New(); + std::vector div(newNbOfNodes); + int spaceDim=getSpaceDimension(); + newCoords->alloc(newNbOfNodes,spaceDim); + newCoords->copyStringInfoFrom(*_coords); + newCoords->fillWithZero(); + int oldNbOfNodes=getNumberOfNodes(); + double *ptToFill=newCoords->getPointer(); + const double *oldCoordsPtr=_coords->getConstPointer(); + for(int i=0;i()); + div[newNodeNumbers[i]]++; + } + for(int i=0;i(),1./(double)div[i])); + setCoords(newCoords); + newCoords->decrRef(); +} + /*! * This method fills bbox params like that : bbox[0]=XMin, bbox[1]=XMax, bbox[2]=YMin... * The returned bounding box is arranged along trihedron. @@ -513,7 +545,7 @@ void MEDCouplingPointSet::findNodesOnPlane(const double *pt, const double *vec, /*! * merge _coords arrays of m1 and m2 and returns the union. The returned instance is newly created with ref count == 1. */ -DataArrayDouble *MEDCouplingPointSet::mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) +DataArrayDouble *MEDCouplingPointSet::mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception) { int spaceDim=m1->getSpaceDimension(); if(spaceDim!=m2->getSpaceDimension()) @@ -521,6 +553,30 @@ DataArrayDouble *MEDCouplingPointSet::mergeNodesArray(const MEDCouplingPointSet return DataArrayDouble::aggregate(m1->getCoords(),m2->getCoords()); } +DataArrayDouble *MEDCouplingPointSet::mergeNodesArray(const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::mergeNodesArray : input array must be NON EMPTY !"); + std::vector::const_iterator it=ms.begin(); + std::vector coo(ms.size()); + int spaceDim=(*it)->getSpaceDimension(); + coo[0]=(*it++)->getCoords(); + for(int i=1;it!=ms.end();it++,i++) + { + const DataArrayDouble *tmp=(*it)->getCoords(); + if(tmp) + { + if((*it)->getSpaceDimension()==spaceDim) + coo[i]=tmp; + else + throw INTERP_KERNEL::Exception("Mismatch in SpaceDim during call of mergeNodesArray !"); + } + else + throw INTERP_KERNEL::Exception("Empty coords detected during call of mergeNodesArray !"); + } + return DataArrayDouble::aggregate(coo); +} + /*! * Factory to build new instance of instanciable subclasses of MEDCouplingPointSet. * This method is used during unserialization process. diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 21cb749b4..4a51adf5b 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -54,6 +54,7 @@ namespace ParaMEDMEM bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; bool areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const; virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0; + virtual DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0; DataArrayInt *buildPermArrayForMergeNode(int limitNodeId, double precision, bool& areNodesMerged, int& newNbOfNodes) const; std::vector getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception); void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, std::vector& c, std::vector& cI) const throw(INTERP_KERNEL::Exception); @@ -70,7 +71,8 @@ namespace ParaMEDMEM void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) = 0; void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception); - static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2); + static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *mergeNodesArray(const std::vector& ms) throw(INTERP_KERNEL::Exception); static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); static void rotate2DAlg(const double *center, double angle, int nbNodes, double *coords); static void rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, double *coords); @@ -82,6 +84,7 @@ namespace ParaMEDMEM virtual void findBoundaryNodes(std::vector& nodes) const = 0; virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); + virtual void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); virtual bool isEmptyMesh(const std::vector& tinyInfo) const = 0; //! size of returned tinyInfo must be always the same. void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index a150a9cd4..8757e8c10 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -115,6 +115,19 @@ bool MEDCouplingTimeDiscretization::areStrictlyCompatible(const MEDCouplingTimeD return true; } +bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const +{ + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples()) + return false; + return true; +} + bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const { if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) @@ -131,6 +144,21 @@ bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplin return true; } +bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + int nbC1=_array->getNumberOfComponents(); + int nbC2=other->_array->getNumberOfComponents(); + if(nbC1!=nbC2 && nbC2!=1) + return false; + return true; +} + bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const { if(!areStrictlyCompatible(other)) @@ -708,6 +736,22 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDi return otherC!=0; } +bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) + return false; + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + return otherC!=0; +} + +bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) + return false; + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + return otherC!=0; +} + bool MEDCouplingNoTimeLabel::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const { const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); @@ -731,6 +775,36 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCoupli throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !"); DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector& other) const +{ + std::vector a(other.size()); + int i=0; + for(std::vector::const_iterator it=other.begin();it!=other.end();it++,i++) + { + const MEDCouplingNoTimeLabel *itC=dynamic_cast(*it); + if(!itC) + throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !"); + a[i]=itC->getArray(); + } + DataArrayDouble *arr=DataArrayDouble::aggregate(a); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::meld(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr,0); arr->decrRef(); @@ -986,6 +1060,22 @@ bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeD return otherC!=0; } +bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) + return false; + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + return otherC!=0; +} + +bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) + return false; + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + return otherC!=0; +} + bool MEDCouplingWithTimeStep::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); @@ -1030,12 +1120,38 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCoupl throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !"); DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; - ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr,0); arr->decrRef(); - int tmp1,tmp2; - double tmp3=getStartTime(tmp1,tmp2); - ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector& other) const +{ + std::vector a(other.size()); + int i=0; + for(std::vector::const_iterator it=other.begin();it!=other.end();it++,i++) + { + const MEDCouplingWithTimeStep *itC=dynamic_cast(*it); + if(!itC) + throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !"); + a[i]=itC->getArray(); + } + DataArrayDouble *arr=DataArrayDouble::aggregate(a); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::meld(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + ret->setArray(arr,0); + arr->decrRef(); return ret; } @@ -1335,7 +1451,23 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTime bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const { - if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other)) + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) + return false; + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + return otherC!=0; +} + +bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) + return false; + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + return otherC!=0; +} + +bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) return false; const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); return otherC!=0; @@ -1421,19 +1553,44 @@ void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const throw( MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const { - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !"); DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector& other) const +{ + std::vector a(other.size()); + int i=0; + for(std::vector::const_iterator it=other.begin();it!=other.end();it++,i++) + { + const MEDCouplingConstOnTimeInterval *itC=dynamic_cast(*it); + if(!itC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !"); + a[i]=itC->getArray(); + } + DataArrayDouble *arr=DataArrayDouble::aggregate(a); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + ret->setArray(arr,0); + arr->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::meld(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr,0); arr->decrRef(); - int tmp1,tmp2; - double tmp3=getStartTime(tmp1,tmp2); - ret->setStartTime(tmp3,tmp1,tmp2); - tmp3=getEndTime(tmp1,tmp2); - ret->setEndTime(tmp3,tmp1,tmp2); return ret; } @@ -1859,7 +2016,15 @@ bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *o if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; const MEDCouplingLinearTime *otherC=dynamic_cast(other); - return otherC!=0; + if(otherC==0) + return false; + if(_end_array==0 && otherC->_end_array==0) + return true; + if(_end_array==0 || otherC->_end_array==0) + return false; + if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents()) + return false; + return true; } bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const @@ -1878,6 +2043,32 @@ bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDis return otherC!=0; } +bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) + return false; + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(otherC==0) + return false; + if(_end_array==0 && otherC->_end_array==0) + return true; + if(_end_array==0 || otherC->_end_array==0) + return false; + int nbC1=_end_array->getNumberOfComponents(); + int nbC2=otherC->_end_array->getNumberOfComponents(); + if(nbC1!=nbC2 && nbC2!=1) + return false; + return true; +} + +bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) + return false; + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + return otherC!=0; +} + /*! * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples() */ @@ -1938,6 +2129,44 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplin DataArrayDouble *arr1=DataArrayDouble::aggregate(getArray(),other->getArray()); DataArrayDouble *arr2=DataArrayDouble::aggregate(getEndArray(),other->getEndArray()); MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + ret->setArray(arr1,0); + arr1->decrRef(); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector& other) const +{ + std::vector a(other.size()); + std::vector b(other.size()); + int i=0; + for(std::vector::const_iterator it=other.begin();it!=other.end();it++,i++) + { + const MEDCouplingLinearTime *itC=dynamic_cast(*it); + if(!itC) + throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !"); + a[i]=itC->getArray(); + b[i]=itC->getEndArray(); + } + DataArrayDouble *arr=DataArrayDouble::aggregate(a); + DataArrayDouble *arr2=DataArrayDouble::aggregate(b); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + ret->setArray(arr,0); + arr->decrRef(); + ret->setEndArray(arr2,0); + arr2->decrRef(); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !"); + DataArrayDouble *arr1=DataArrayDouble::meld(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::meld(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr1,0); arr1->decrRef(); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index e826e12ce..88b020eb1 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -46,6 +46,8 @@ namespace ParaMEDMEM virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const; virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; + virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + virtual bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other, @@ -53,6 +55,8 @@ namespace ParaMEDMEM virtual std::string getStringRepr() const = 0; virtual TypeOfTimeDiscretization getEnum() const = 0; virtual MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const = 0; + virtual MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const = 0; + virtual MEDCouplingTimeDiscretization *meld(const MEDCouplingTimeDiscretization *other) const = 0; virtual MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const = 0; virtual MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const = 0; virtual MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const = 0; @@ -133,6 +137,8 @@ namespace ParaMEDMEM std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const; + MEDCouplingTimeDiscretization *meld(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; @@ -150,6 +156,8 @@ namespace ParaMEDMEM bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; + bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const; void checkNoTimePresence() const throw(INTERP_KERNEL::Exception) { } void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception); @@ -180,6 +188,8 @@ namespace ParaMEDMEM void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const; + MEDCouplingTimeDiscretization *meld(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; @@ -197,6 +207,8 @@ namespace ParaMEDMEM bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; + bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; void getTinySerializationIntInformation(std::vector& tinyInfo) const; void getTinySerializationDbleInformation(std::vector& tinyInfo) const; void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); @@ -236,6 +248,8 @@ namespace ParaMEDMEM bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; + bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; std::vector< const DataArrayDouble *> getArraysForTime(double time) const throw(INTERP_KERNEL::Exception); @@ -245,6 +259,8 @@ namespace ParaMEDMEM TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } std::string getStringRepr() const; MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const; + MEDCouplingTimeDiscretization *meld(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; @@ -331,10 +347,14 @@ namespace ParaMEDMEM bool areCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const; bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; + bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; void getValueForTime(double time, const std::vector& vals, double *res) const; void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception); MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; + MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const; + MEDCouplingTimeDiscretization *meld(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *dot(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *crossProduct(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *max(const MEDCouplingTimeDiscretization *other) const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 2fb724a8d..02a5a5871 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -154,14 +154,25 @@ void MEDCouplingUMesh::allocateCells(int nbOfCells) * @param size number of nodes constituting this cell. * @param nodalConnOfCell the connectivity of the cell to add. */ -void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) +void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) throw(INTERP_KERNEL::Exception) { - int *pt=_nodal_connec_index->getPointer(); - int idx=pt[_iterator]; - - _nodal_connec->writeOnPlace(idx,type,nodalConnOfCell,size); - _types.insert(type); - pt[++_iterator]=idx+size+1; + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(type); + if((int)cm.getDimension()==_mesh_dim) + { + int *pt=_nodal_connec_index->getPointer(); + int idx=pt[_iterator]; + + _nodal_connec->writeOnPlace(idx,type,nodalConnOfCell,size); + _types.insert(type); + pt[++_iterator]=idx+size+1; + } + else + { + std::ostringstream oss; oss << "MEDCouplingUMesh::insertNextCell : cell type " << cm.getRepr() << " has a dimension " << cm.getDimension(); + oss << " whereas Mesh Dimension of current UMesh instance is set to " << _mesh_dim << " ! Please invoke \"setMeshDimension\" method before or invoke "; + oss << "\"MEDCouplingUMesh::New\" static method with 2 parameters name and meshDimension !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } /*! @@ -358,7 +369,7 @@ void MEDCouplingUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double * \b WARNING this method do the assumption that connectivity lies on the coordinates set. * For speed reasons no check of this will be done. */ -void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const +void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); int nbOfNodes=getNumberOfNodes(); @@ -398,7 +409,7 @@ void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataA * \b WARNING this method do the assumption that connectivity lies on the coordinates set. * For speed reasons no check of this will be done. */ -MEDCouplingUMesh *MEDCouplingUMesh::buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const +MEDCouplingUMesh *MEDCouplingUMesh::buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); int nbOfCells=getNumberOfCells(); @@ -624,7 +635,7 @@ void MEDCouplingUMesh::unPolyze() * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes. * -1 values in returned array means that the corresponding old node is no more used. */ -DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() +DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() throw(INTERP_KERNEL::Exception) { int nbOfNodes=getNumberOfNodes(); DataArrayInt *ret=DataArrayInt::New(); @@ -827,7 +838,7 @@ void MEDCouplingUMesh::findCommonCellsBase(int compType, std::vector& res, * 2 : nodal. cell1 and cell2 are equal if and only if cell1 and cell2 have same type and have the same nodes constituting connectivity. This is the laziest policy. * @return the correspondance array old to new. */ -DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType) +DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception) { int spaceDim=getSpaceDimension(); int nbOfCells=getNumberOfCells(); @@ -895,6 +906,25 @@ DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType) return ret; } +/*! + * This method makes the assumption that 'this' and 'other' share the same coords. If not an exception will be thrown ! + * This method tries to determine if 'other' is fully included in 'this'. To compute that, this method works with connectivity as MEDCouplingUMesh::zipConnectivityTraducer method does. + * This method has two outputs : + * + * @param compType is the comparison type. The possible values of this parameter are described in ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer method + * @param arr is an output parameter that returns a \b newly created instance. This array is of size 'other->getNumberOfCells()'. + * @return If 'other' is fully included in 'this 'true is returned. If not false is returned. + */ +bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr mesh=mergeUMeshesOnSameCoords(this,other); + MEDCouplingAutoRefCountObjectPtr o2n=mesh->zipConnectivityTraducer(compType); + int nbOfCells=getNumberOfCells(); + arr=o2n->substr(nbOfCells); + int tmp; + return arr->getMaxValue(tmp)getConstPointer(),newNbOfNodes); + return ret; +} + /*! * This method tries to use 'other' coords and use it for 'this'. If no exception was thrown after the call of this method : * this->_coords==other->_coords. If not a exception is thrown this remains unchanged. @@ -947,7 +988,7 @@ void MEDCouplingUMesh::tryToShareSameCoordsPermute(const MEDCouplingPointSet& ot * build a sub part of 'this'. This sub part is defined by the cell ids contained in the array in [begin,end). * @param begin begin of array containing the cell ids to keep. * @param end end of array of cell ids to keep. \b WARNING end param is \b not included ! Idem STL standard definitions. - * @param keepCoords that specifies if you want or not to keep coords as this or zip it (see zipCoords) + * @param keepCoords that specifies if you want or not to keep coords as this or zip it (see ParaMEDMEM::MEDCouplingUMesh::zipCoords). If true zipCoords is \b NOT called, if false, zipCoords is called. */ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelf(const int *begin, const int *end, bool keepCoords) const { @@ -1042,7 +1083,7 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildFacePartOfMySelfNode(const int *begi /*! * This method returns a mesh with meshDim=this->getMeshDimension()-1. * This returned mesh contains cells that are linked with one and only one cell of this. - * @param keepCoords specifies if zipCoords is called on returned mesh before being returned. + * @param keepCoords specifies if ParaMEDMEM::MEDCouplingUMesh::zipCoords is called on returned mesh before being returned. If true zipCoords is \b NOT called, if false, zipCoords is called. * @return mesh with ref counter equal to 1. */ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const @@ -1101,6 +1142,12 @@ void MEDCouplingUMesh::findBoundaryNodes(std::vector& nodes) const meshDM1->decrRef(); } +MEDCouplingUMesh *MEDCouplingUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) +{ + incrRef(); + return const_cast(this); +} + /* * This method renumber 'this' using 'newNodeNumbers' array of size this->getNumberOfNodes. * newNbOfNodes specifies the *std::max_element(newNodeNumbers,newNodeNumbers+this->getNumberOfNodes()) @@ -1116,6 +1163,22 @@ void MEDCouplingUMesh::renumberNodes(const int *newNodeNumbers, int newNbOfNodes renumberNodesInConn(newNodeNumbers); } +/* + * This method renumber 'this' using 'newNodeNumbers' array of size this->getNumberOfNodes. + * newNbOfNodes specifies the *std::max_element(newNodeNumbers,newNodeNumbers+this->getNumberOfNodes()) + * This value is asked because often known by the caller of this method. + * This method, contrary to MEDCouplingMesh::renumberCells does NOT conserve the number of nodes before and after. + * The difference with ParaMEDMEM::MEDCouplingUMesh::renumberNodes method is in the fact that the barycenter of merged nodes is computed here. + * + * @param newNodeNumbers array specifying the new numbering. + * @param newNbOfNodes the new number of nodes. + */ +void MEDCouplingUMesh::renumberNodes2(const int *newNodeNumbers, int newNbOfNodes) +{ + MEDCouplingPointSet::renumberNodes2(newNodeNumbers,newNbOfNodes); + renumberNodesInConn(newNodeNumbers); +} + /*! * This method renumbers nodes in connectivity only without any reference with coords. * Use it with care ! @@ -1728,35 +1791,52 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons */ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const { - if(getMeshDimension()!=2) - throw INTERP_KERNEL::Exception("Expected a umesh with meshDim == 2 !"); + if((getMeshDimension()!=2) && (getMeshDimension()!=1 || getSpaceDimension()!=2)) + throw INTERP_KERNEL::Exception("Expected a umesh with ( meshDim == 2 spaceDim == 2 or 3 ) or ( meshDim == 1 spaceDim == 2 ) !"); MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME); DataArrayDouble *array=DataArrayDouble::New(); int nbOfCells=getNumberOfCells(); - array->alloc(nbOfCells,3); + int nbComp=getMeshDimension()+1; + array->alloc(nbOfCells,nbComp); double *vals=array->getPointer(); const int *connI=_nodal_connec_index->getConstPointer(); const int *conn=_nodal_connec->getConstPointer(); const double *coords=_coords->getConstPointer(); - DataArrayDouble *loc=getBarycenterAndOwner(); - const double *locPtr=loc->getConstPointer(); - if(getSpaceDimension()==3) + if(getMeshDimension()==2) { - for(int i=0;i(locPtr+3*i,coords+3*conn[offset+1],coords+3*conn[offset+2],vals); - double n=INTERP_KERNEL::norm<3>(vals); - std::transform(vals,vals+3,vals,std::bind2nd(std::multiplies(),1./n)); + DataArrayDouble *loc=getBarycenterAndOwner(); + const double *locPtr=loc->getConstPointer(); + for(int i=0;i(locPtr+3*i,coords+3*conn[offset+1],coords+3*conn[offset+2],vals); + double n=INTERP_KERNEL::norm<3>(vals); + std::transform(vals,vals+3,vals,std::bind2nd(std::multiplies(),1./n)); + } + loc->decrRef(); + } + else + { + for(int i=0;i()); + double n=INTERP_KERNEL::norm<2>(tmp); + std::transform(tmp,tmp+2,tmp,std::bind2nd(std::multiplies(),1./n)); + *vals++=-tmp[1]; + *vals++=tmp[0]; + } } ret->setArray(array); - loc->decrRef(); array->decrRef(); ret->setMesh(this); return ret; @@ -2015,18 +2095,18 @@ void MEDCouplingUMesh::checkButterflyCells(std::vector& cells) const * \b 1 for translation and rotation around point of 'mesh1D'. * @return an unstructured mesh with meshDim==3 and spaceDim==3. The returned mesh has the same coords than 'this'. */ -MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy) +MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy) { checkFullyDefined(); mesh1D->checkFullyDefined(); if(!mesh1D->isContiguous1D()) - throw INTERP_KERNEL::Exception("buildExtrudedMeshFromThis : 1D mesh passed in parameter is not contiguous !"); + throw INTERP_KERNEL::Exception("buildExtrudedMesh : 1D mesh passed in parameter is not contiguous !"); if(getSpaceDimension()!=mesh1D->getSpaceDimension()) - throw INTERP_KERNEL::Exception("Invalid call to buildExtrudedMeshFromThis this and mesh1D must have same dimension !"); + throw INTERP_KERNEL::Exception("Invalid call to buildExtrudedMesh this and mesh1D must have same dimension !"); if((getMeshDimension()!=2 || getSpaceDimension()!=3) && (getMeshDimension()!=1 || getSpaceDimension()!=2)) - throw INTERP_KERNEL::Exception("Invalid 'this' for buildExtrudedMeshFromThis method : must be (meshDim==2 and spaceDim==3) or (meshDim==1 and spaceDim==2) !"); + throw INTERP_KERNEL::Exception("Invalid 'this' for buildExtrudedMesh method : must be (meshDim==2 and spaceDim==3) or (meshDim==1 and spaceDim==2) !"); if(mesh1D->getMeshDimension()!=1) - throw INTERP_KERNEL::Exception("Invalid 'mesh1D' for buildExtrudedMeshFromThis method : must be meshDim==1 !"); + throw INTERP_KERNEL::Exception("Invalid 'mesh1D' for buildExtrudedMesh method : must be meshDim==1 !"); bool isQuad=false; if(isPresenceOfQuadratic()) { @@ -2061,7 +2141,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThis(const MEDCouplingU } /*! - * This method incarnates the policy 0 for MEDCouplingUMesh::buildExtrudedMeshFromThis method. + * This method incarnates the policy 0 for MEDCouplingUMesh::buildExtrudedMesh method. * @param mesh1D is the input 1D mesh used for translation computation. * @return newCoords new coords filled by this method. */ @@ -2107,7 +2187,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslation(const MEDCoupli } /*! - * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMeshFromThis method. + * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method. * @param mesh1D is the input 1D mesh used for translation and automatic rotation computation. * @return newCoords new coords filled by this method. */ @@ -2121,7 +2201,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation(const } /*! - * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMeshFromThis method. + * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method. * @param mesh1D is the input 1D mesh used for translation and automatic rotation computation. * @return newCoords new coords filled by this method. */ @@ -2139,7 +2219,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(con double *retPtr=ret->getPointer(); retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr); MEDCouplingUMesh *tmp=MEDCouplingUMesh::New(); - DataArrayDouble *tmp2=getCoords()->deepCopy(); + DataArrayDouble *tmp2=getCoords()->deepCpy(); tmp->setCoords(tmp2); tmp2->decrRef(); const double *coo1D=mesh1D->getCoords()->getConstPointer(); @@ -2167,7 +2247,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(con } /*! - * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMeshFromThis method. + * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method. * @param mesh1D is the input 1D mesh used for translation and automatic rotation computation. * @return newCoords new coords filled by this method. */ @@ -2185,7 +2265,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(con double *retPtr=ret->getPointer(); retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr); MEDCouplingUMesh *tmp=MEDCouplingUMesh::New(); - DataArrayDouble *tmp2=getCoords()->deepCopy(); + DataArrayDouble *tmp2=getCoords()->deepCpy(); tmp->setCoords(tmp2); tmp2->decrRef(); const double *coo1D=mesh1D->getCoords()->getConstPointer(); @@ -2237,7 +2317,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(con /*! * This method is private because not easy to use for end user. This method is const contrary to - * MEDCouplingUMesh::buildExtrudedMeshFromThis method because this->_coords are expected to contain + * MEDCouplingUMesh::buildExtrudedMesh method because this->_coords are expected to contain * the coords sorted slice by slice. * @param isQuad specifies presence of quadratic cells. */ @@ -3085,7 +3165,7 @@ DataArrayInt *MEDCouplingUMesh::rearrange2ConsecutiveCellTypes() } /*! - * This methods split this into as mush as untructured meshes that consecutive set of same type cells. + * This method splits 'this' into as mush as untructured meshes that consecutive set of same type cells. * So this method has typically a sense if MEDCouplingUMesh::checkConsecutiveCellTypes has a sense. * This method makes asumption that connectivity is correctly set before calling. */ @@ -3215,44 +3295,83 @@ DataArrayDouble *MEDCouplingUMesh::getBarycenterAndOwner() const * Returns a newly created mesh (with ref count ==1) that contains merge of 'mesh1' and 'other'. * The coords of 'mesh2' are added at the end of coords of 'mesh1'. */ -MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) +MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception) { - MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); - ret->setName("merge"); - DataArrayDouble *pts=mergeNodesArray(mesh1,mesh2); + std::vector tmp(2); + tmp[0]=const_cast(mesh1); tmp[1]=const_cast(mesh2); + return mergeUMeshes(tmp); +} + +MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(std::vector& a) throw(INTERP_KERNEL::Exception) +{ + if(a.empty()) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::mergeUMeshes : input array must be NON EMPTY !"); + std::vector::const_iterator it=a.begin(); + int meshDim=(*it)->getMeshDimension(); + int nbOfCells=(*it)->getNumberOfCells(); + int meshLgth=(*it++)->getMeshLength(); + for(;it!=a.end();it++) + { + if(meshDim!=(*it)->getMeshDimension()) + throw INTERP_KERNEL::Exception("Mesh dimensions mismatches, mergeMeshes impossible !"); + nbOfCells+=(*it)->getNumberOfCells(); + meshLgth+=(*it)->getMeshLength(); + } + std::vector aps(a.size()); + std::copy(a.begin(),a.end(),aps.begin()); + DataArrayDouble *pts=mergeNodesArray(aps); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New("merge",meshDim); ret->setCoords(pts); pts->decrRef(); - int meshDim=mesh1->getMeshDimension(); - if(meshDim!=mesh2->getMeshDimension()) - throw INTERP_KERNEL::Exception("Mesh dimensions mismatches, mergeMeshes impossible !"); - ret->setMeshDimension(meshDim); - int delta=mesh1->getMeshLength(); - int pos=mesh1->getNumberOfCells(); - int nbOfCells2=mesh2->getNumberOfCells(); - int end=mesh1->getNumberOfCells()+nbOfCells2+1; - DataArrayInt *nodalIndex=DataArrayInt::aggregate(mesh1->getNodalConnectivityIndex(), - mesh2->getNodalConnectivityIndex(),1); - std::transform(nodalIndex->getConstPointer()+pos+1,nodalIndex->getConstPointer()+end, - nodalIndex->getPointer()+pos+1,std::bind2nd(std::plus(),delta)); - DataArrayInt *newNodal2=mesh2->getNodalConnectivity()->deepCopy(); - delta=mesh1->getNumberOfNodes(); - const int *nI2=mesh2->getNodalConnectivityIndex()->getConstPointer(); - int *pt=newNodal2->getPointer(); - for(int i=0;igetNodalConnectivity(),newNodal2,0); - newNodal2->decrRef(); - ret->setConnectivity(nodal,nodalIndex,true); - nodalIndex->decrRef(); - nodal->decrRef(); + DataArrayInt *c=DataArrayInt::New(); + c->alloc(meshLgth,1); + int *cPtr=c->getPointer(); + DataArrayInt *cI=DataArrayInt::New(); + cI->alloc(nbOfCells+1,1); + int *cIPtr=cI->getPointer(); + *cIPtr++=0; + int offset=0; + int offset2=0; + for(it=a.begin();it!=a.end();it++) + { + int curNbOfCell=(*it)->getNumberOfCells(); + const int *curCI=(*it)->_nodal_connec_index->getConstPointer(); + const int *curC=(*it)->_nodal_connec->getConstPointer(); + cIPtr=std::transform(curCI+1,curCI+curNbOfCell+1,cIPtr,std::bind2nd(std::plus(),offset)); + for(int j=0;jgetNumberOfNodes(); + } + // + ret->setConnectivity(c,cI,true); + c->decrRef(); + cI->decrRef(); + ret->incrRef(); return ret; } +/*! + * Idem mergeUMeshes except that 'meshes' are expected to lyie on the same coords and 'meshes' have the same meshdim. + * 'meshes' must be a non empty vector. + */ +MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(2); + tmp[0]=const_cast(mesh1); tmp[1]=const_cast(mesh2); + return mergeUMeshesOnSameCoords(tmp); +} + /*! * Idem mergeUMeshes except that 'meshes' are expected to lyie on the same coords and 'meshes' have the same meshdim. * 'meshes' must be a non empty vector. diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index df4ddd292..3594338ea 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -47,7 +47,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void checkCoherency() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setMeshDimension(int meshDim); MEDCOUPLING_EXPORT void allocateCells(int nbOfCells); - MEDCOUPLING_EXPORT void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell); + MEDCOUPLING_EXPORT void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void finishInsertingCells(); MEDCOUPLING_EXPORT const std::set& getAllTypes() const { return _types; } MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); @@ -80,18 +80,22 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int cellId, double prec) const; MEDCOUPLING_EXPORT void convertToPolyTypes(const std::vector& cellIdsToConvert); MEDCOUPLING_EXPORT void unPolyze(); - MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer(); - MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType); - MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const; - MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; + MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes); + MEDCOUPLING_EXPORT DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes); MEDCOUPLING_EXPORT void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelf(const int *begin, const int *end, bool keepCoords) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; + MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector& nodes) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); + MEDCOUPLING_EXPORT void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems); MEDCOUPLING_EXPORT void giveElemsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems); @@ -106,7 +110,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; MEDCOUPLING_EXPORT void checkButterflyCells(std::vector& cells) const; MEDCOUPLING_EXPORT void getBoundingBoxForBBTree(std::vector& bbox) const; - MEDCOUPLING_EXPORT MEDCouplingUMesh *buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy); + MEDCOUPLING_EXPORT MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy); MEDCOUPLING_EXPORT bool isFullyQuadratic() const; MEDCOUPLING_EXPORT bool isPresenceOfQuadratic() const; MEDCOUPLING_EXPORT void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); @@ -134,7 +138,9 @@ namespace ParaMEDMEM // MEDCOUPLING_EXPORT MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const; MEDCOUPLING_EXPORT DataArrayDouble *getBarycenterAndOwner() const; - MEDCOUPLING_EXPORT static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); + MEDCOUPLING_EXPORT static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCouplingUMesh *mergeUMeshes(std::vector& a) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCouplingUMesh *mergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static MEDCouplingUMesh *mergeUMeshesOnSameCoords(const std::vector& meshes); MEDCOUPLING_EXPORT static MEDCouplingUMesh *fuseUMeshesOnSameCoords(const std::vector& meshes, int compType, std::vector& corr); MEDCOUPLING_EXPORT static bool isPolygonWellOriented(const double *vec, const int *begin, const int *end, const double *coords); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index e8629b7b8..e0cff180d 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -338,6 +338,13 @@ DataArrayInt *MEDCouplingUMeshDesc::mergeNodes(double precision, bool& areNodesM return 0; } +DataArrayInt *MEDCouplingUMeshDesc::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes) +{ + //not implemented yet. + areNodesMerged=false; + return 0; +} + void MEDCouplingUMeshDesc::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Not implemented yet !"); @@ -377,6 +384,11 @@ MEDCouplingPointSet *MEDCouplingUMeshDesc::buildBoundaryMesh(bool keepCoords) co return 0; } +MEDCouplingUMesh *MEDCouplingUMeshDesc::buildUnstructured() const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::buildUnstructured : not implemented yet !"); +} + void MEDCouplingUMeshDesc::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Available for UMesh desc but not implemented yet !"); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index f11fe94a4..1924108e9 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -62,6 +62,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems); MEDCOUPLING_EXPORT void giveElemsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps, std::vector& elems); MEDCOUPLING_EXPORT DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes); + MEDCOUPLING_EXPORT DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes); MEDCOUPLING_EXPORT void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const; @@ -69,6 +70,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector& nodes) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; + MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 4982c2e7a..54bcaa886 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -160,6 +160,22 @@ namespace ParaMEDMEM CPPUNIT_TEST( testExtrudedMesh7 ); CPPUNIT_TEST( testSimplexize1 ); CPPUNIT_TEST( testSimplexize2 ); + CPPUNIT_TEST( testDAMeld1 ); + CPPUNIT_TEST( testFieldMeld1 ); + CPPUNIT_TEST( testMergeNodes2 ); + CPPUNIT_TEST( testMergeField2 ); + CPPUNIT_TEST( testDAIBuildComplement1 ); + CPPUNIT_TEST( testDAIBuildUnion1 ); + CPPUNIT_TEST( testDAIBuildIntersection1 ); + CPPUNIT_TEST( testDAIDeltaShiftIndex1 ); + CPPUNIT_TEST( testDaDoubleSelectByTupleIdSafe1 ); + CPPUNIT_TEST( testAreCellsIncludedIn1 ); + CPPUNIT_TEST( testDAIBuildSubstraction1 ); + CPPUNIT_TEST( testBuildOrthogonalField2 ); + CPPUNIT_TEST( testUMInsertNextCell1 ); + CPPUNIT_TEST( testFieldOperatorDivDiffComp1 ); + CPPUNIT_TEST( testDARearrange1 ); + CPPUNIT_TEST( testGetDifferentValues1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -348,6 +364,22 @@ namespace ParaMEDMEM void testExtrudedMesh7(); void testSimplexize1(); void testSimplexize2(); + void testDAMeld1(); + void testFieldMeld1(); + void testMergeNodes2(); + void testMergeField2(); + void testDAIBuildComplement1(); + void testDAIBuildUnion1(); + void testDAIBuildIntersection1(); + void testDAIDeltaShiftIndex1(); + void testDaDoubleSelectByTupleIdSafe1(); + void testAreCellsIncludedIn1(); + void testDAIBuildSubstraction1(); + void testBuildOrthogonalField2(); + void testUMInsertNextCell1(); + void testFieldOperatorDivDiffComp1(); + void testDARearrange1(); + void testGetDifferentValues1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index ffa8b6a75..98f0f6b72 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -325,7 +325,7 @@ void MEDCouplingBasicsTest::testDeepCopy() std::fill(array->getPointer(),array->getPointer()+5*3,7.); CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14); double *tmp1=array->getPointer(); - DataArrayDouble *array2=array->deepCopy(); + DataArrayDouble *array2=array->deepCpy(); double *tmp2=array2->getPointer(); CPPUNIT_ASSERT(tmp1!=tmp2); array->decrRef(); @@ -337,7 +337,7 @@ void MEDCouplingBasicsTest::testDeepCopy() std::fill(array3->getPointer(),array3->getPointer()+5*3,17); CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2)); int *tmp3=array3->getPointer(); - DataArrayInt *array4=array3->deepCopy(); + DataArrayInt *array4=array3->deepCpy(); int *tmp4=array4->getPointer(); CPPUNIT_ASSERT(tmp3!=tmp4); array3->decrRef(); @@ -873,7 +873,7 @@ void MEDCouplingBasicsTest::testEqualFieldDouble() CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15)); // - DataArrayDouble *arr2=arr->deepCopy(); + DataArrayDouble *arr2=arr->deepCpy(); fieldOnCells2->setArray(arr2); arr2->decrRef(); CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15)); @@ -1049,7 +1049,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh2() } /*! - * This test check MEDCouplingUMesh::buildExtrudedMeshFromThis method. + * This test check MEDCouplingUMesh::buildExtrudedMesh method. */ void MEDCouplingBasicsTest::testExtrudedMesh3() { @@ -1060,7 +1060,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh3() double center[3]={0.,0.,0.}; double vector[3]={0,1,0}; m2->rotate(center,vector,-M_PI/2.); - MEDCouplingUMesh *m3=m1->buildExtrudedMeshFromThis(m2,0); + MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0); // MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0); CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells()); @@ -1085,7 +1085,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh3() //play with polygons and polyedrons std::vector cells(2); cells[0]=2; cells[1]=3; m1->convertToPolyTypes(cells); - m3=m1->buildExtrudedMeshFromThis(m2,0); + m3=m1->buildExtrudedMesh(m2,0); CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0)); CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1)); CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2)); @@ -1107,7 +1107,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh3() } /*! - * This test check MEDCouplingUMesh::buildExtrudedMeshFromThis method, but also, MEDCouplingExtrudedMesh following methods : + * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingExtrudedMesh following methods : * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh. */ void MEDCouplingBasicsTest::testExtrudedMesh4() @@ -1121,7 +1121,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh4() double center[3]={0.,0.,0.}; double vector[3]={0.,1.,0.}; m2->rotate(center,vector,-M_PI/2.); - MEDCouplingUMesh *m3=m1->buildExtrudedMeshFromThis(m2,0); + MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0); const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4}; const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12}; m3->renumberCells(expected1,false); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 2b2f4de2a..6bbc8b209 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -215,7 +215,7 @@ void MEDCouplingBasicsTest::testCellOrientation2() double center[3]={0.,0.,0.}; double vector[3]={0.,1.,0.}; m4->rotate(center,vector,-M_PI/2.); - MEDCouplingUMesh *m5=m3->buildExtrudedMeshFromThis(m4,0); + MEDCouplingUMesh *m5=m3->buildExtrudedMesh(m4,0); res1.clear(); m5->arePolyhedronsNotCorrectlyOriented(res1); CPPUNIT_ASSERT_EQUAL(15,(int)res1.size()); @@ -902,7 +902,7 @@ void MEDCouplingBasicsTest::testCopyTinyStringsFromOnFields() a1->fillWithZero(); a1->setInfoOnComponent(0,"c"); a1->setInfoOnComponent(1,"d"); - DataArrayDouble *a2=a1->deepCopy(); + DataArrayDouble *a2=a1->deepCpy(); a2->setInfoOnComponent(0,"e"); a2->setInfoOnComponent(1,"f"); f->setArray(a1); @@ -3376,7 +3376,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh5() DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec"); DataArrayDouble *h=g->fromPolarToCart(); f->setCoords(h); - MEDCouplingUMesh *i=c->buildExtrudedMeshFromThis(f,1); + MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1); CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes()); bool tmp2; int tmp3; @@ -3440,7 +3440,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh6() // const double center[2]={0.,0.}; f->rotate(center,0,M_PI/3); - MEDCouplingUMesh *g=c->buildExtrudedMeshFromThis(f,0); + MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0); g->checkCoherency(); const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 }; MEDCouplingFieldDouble *f1=g->getMeasureField(true); @@ -3488,7 +3488,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh7() DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec"); DataArrayDouble *h=g->fromPolarToCart(); f->setCoords(h); - MEDCouplingUMesh *i=c->buildExtrudedMeshFromThis(f,1); + MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1); CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes()); bool tmp2; int tmp3; @@ -3502,7 +3502,7 @@ void MEDCouplingBasicsTest::testExtrudedMesh7() DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec"); f->setCoords(g2); i->changeSpaceDimension(3); - MEDCouplingUMesh *i3=i->buildExtrudedMeshFromThis(f,1); + MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1); MEDCouplingFieldDouble *f2=i3->getMeasureField(true); tmp=i->mergeNodes(1e-9,tmp2,tmp3); CPPUNIT_ASSERT(tmp2); @@ -3618,3 +3618,561 @@ void MEDCouplingBasicsTest::testSimplexize2() f1->decrRef(); m->decrRef(); } + +void MEDCouplingBasicsTest::testDAMeld1() +{ + DataArrayDouble *da1=DataArrayDouble::New(); + da1->alloc(7,2); + DataArrayDouble *da2=DataArrayDouble::New(); + da2->alloc(7,1); + // + da1->fillWithValue(7.); + da2->iota(0.); + DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec"); + // + da1->setInfoOnComponent(0,"c0da1"); + da1->setInfoOnComponent(1,"c1da1"); + da3->setInfoOnComponent(0,"c0da3"); + da3->setInfoOnComponent(1,"c1da3"); + da3->setInfoOnComponent(2,"c2da3"); + // + DataArrayDouble *da1C=da1->deepCpy(); + da1->meldWith(da3); + CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples()); + CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1"); + CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1"); + CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3"); + CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3"); + CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3"); + // + const double expected1[35]={7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.}; + for(int i=0;i<35;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10); + // + DataArrayInt *dai1=da1C->convertToIntArr(); + DataArrayInt *dai3=da3->convertToIntArr(); + dai1->meldWith(dai3); + CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples()); + CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1"); + CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1"); + CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3"); + CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3"); + CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3"); + for(int i=0;i<35;i++) + CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i)); + // test of static method DataArrayDouble::meld + DataArrayDouble *da4=DataArrayDouble::meld(da1C,da3); + CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples()); + CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1"); + CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1"); + CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3"); + CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3"); + CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3"); + for(int i=0;i<35;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10); + // test of static method DataArrayInt::meld + dai1->decrRef(); + dai1=da1C->convertToIntArr(); + DataArrayInt *dai4=DataArrayInt::meld(dai1,dai3); + CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples()); + CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1"); + CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1"); + CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3"); + CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3"); + CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3"); + for(int i=0;i<35;i++) + CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i)); + // + dai4->decrRef(); + da4->decrRef(); + dai3->decrRef(); + dai1->decrRef(); + da1C->decrRef(); + da1->decrRef(); + da2->decrRef(); + da3->decrRef(); +} + +void MEDCouplingBasicsTest::testFieldMeld1() +{ + MEDCouplingUMesh *m=build3DSurfTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setMesh(m); + DataArrayDouble *da1=DataArrayDouble::New(); + const double arr1[5]={12.,23.,34.,45.,56.}; + da1->alloc(5,1); + std::copy(arr1,arr1+5,da1->getPointer()); + da1->setInfoOnComponent(0,"aaa"); + f1->setArray(da1); + f1->setTime(3.4,2,1); + f1->checkCoherency(); + // + MEDCouplingFieldDouble *f2=f1->deepCpy(); + f2->setMesh(f1->getMesh()); + f2->checkCoherency(); + f2->changeNbOfComponents(2,5.); + (*f2)=5.; + f2->getArray()->setInfoOnComponent(0,"bbb"); + f2->getArray()->setInfoOnComponent(1,"ccc"); + f2->checkCoherency(); + // + MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::meldFields(f2,f1); + f3->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents()); + CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb"); + CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc"); + CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa"); + const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.}; + for(int i=0;i<15;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12); + int dt,it; + double time=f3->getTime(dt,it); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14); + CPPUNIT_ASSERT_EQUAL(2,dt); + CPPUNIT_ASSERT_EQUAL(1,it); + // + MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false); + MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false); + MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::meldFields(f4,f5); + f6->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents()); + CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb"); + CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc"); + CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa"); + for(int i=0;i<15;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12); + // + f6->decrRef(); + f4->decrRef(); + f5->decrRef(); + f3->decrRef(); + da1->decrRef(); + f2->decrRef(); + f1->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testMergeNodes2() +{ + MEDCouplingUMesh *m1=build2DTargetMesh_1(); + MEDCouplingUMesh *m2=build2DTargetMesh_1(); + const double vec[2]={0.002,0.}; + m2->translate(vec); + // + std::vector tmp(2); + tmp[0]=m1; + tmp[1]=m2; + MEDCouplingUMesh *m3=MEDCouplingUMesh::mergeUMeshes(tmp); + bool b; + int newNbOfNodes; + DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes); + CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes()); + const double expected1[18]={-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7}; + for(int i=0;i<18;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13); + // + da->decrRef(); + m3->decrRef(); + m1->decrRef(); + m2->decrRef(); +} + +void MEDCouplingBasicsTest::testMergeField2() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setMesh(m); + DataArrayDouble *arr=DataArrayDouble::New(); + arr->alloc(5,2); + arr->fillWithValue(2.); + f1->setArray(arr); + arr->decrRef(); + MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f2->setMesh(m); + arr=DataArrayDouble::New(); + arr->alloc(5,2); + arr->fillWithValue(5.); + f2->setArray(arr); + arr->decrRef(); + MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f3->setMesh(m); + arr=DataArrayDouble::New(); + arr->alloc(5,2); + arr->fillWithValue(7.); + f3->setArray(arr); + arr->decrRef(); + // + std::vector tmp(3); + tmp[0]=f1; tmp[1]=f2; tmp[2]=f3; + MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::mergeFields(tmp); + CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells()); + const double expected1[30]={2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13); + // + f4->decrRef(); + f1->decrRef(); + f2->decrRef(); + f3->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIBuildComplement1() +{ + DataArrayInt *a=DataArrayInt::New(); + const int tab[4]={3,1,7,8}; + a->alloc(4,1); + std::copy(tab,tab+4,a->getPointer()); + DataArrayInt *b=a->buildComplement(12); + CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents()); + const int expected1[8]={0,2,4,5,6,9,10,11}; + for(int i=0;i<8;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i)); + b->decrRef(); + a->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIBuildUnion1() +{ + DataArrayInt *a=DataArrayInt::New(); + const int tab1[4]={3,1,7,8}; + a->alloc(4,1); + std::copy(tab1,tab1+4,a->getPointer()); + DataArrayInt *c=DataArrayInt::New(); + const int tab2[5]={5,3,0,18,8}; + c->alloc(5,1); + std::copy(tab2,tab2+5,c->getPointer()); + DataArrayInt *b=a->buildUnion(c); + CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents()); + const int expected1[7]={0,1,3,5,7,8,18}; + for(int i=0;i<7;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i)); + c->decrRef(); + b->decrRef(); + a->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIBuildIntersection1() +{ + DataArrayInt *a=DataArrayInt::New(); + const int tab1[4]={3,1,7,8}; + a->alloc(4,1); + std::copy(tab1,tab1+4,a->getPointer()); + DataArrayInt *c=DataArrayInt::New(); + const int tab2[5]={5,3,0,18,8}; + c->alloc(5,1); + std::copy(tab2,tab2+5,c->getPointer()); + DataArrayInt *b=a->buildIntersection(c); + CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents()); + const int expected1[2]={3,8}; + for(int i=0;i<2;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i)); + c->decrRef(); + b->decrRef(); + a->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIDeltaShiftIndex1() +{ + DataArrayInt *a=DataArrayInt::New(); + const int tab[7]={1,3,6,7,7,9,15}; + a->alloc(7,1); + std::copy(tab,tab+7,a->getPointer()); + DataArrayInt *b=a->deltaShiftIndex(); + CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents()); + const int expected1[6]={2,3,1,0,2,6}; + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i)); + b->decrRef(); + a->decrRef(); +} + +void MEDCouplingBasicsTest::testDaDoubleSelectByTupleIdSafe1() +{ + 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->selectByTupleIdSafe(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); + const int arr4[5]={4,-1,0,6,5}; + CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception); + const int arr5[5]={4,2,0,6,7}; + CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception); + 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->selectByTupleIdSafe(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)); + CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception); + c->decrRef(); + d->decrRef(); +} + +void MEDCouplingBasicsTest::testAreCellsIncludedIn1() +{ + MEDCouplingUMesh *m=build3DSurfTargetMesh_1(); + const int pt[2]={1,3}; + MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true); + DataArrayInt *tmp; + CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp)); + CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1)); + tmp->decrRef(); + CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp)); + tmp->decrRef(); + m2->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIBuildSubstraction1() +{ + DataArrayInt *a=DataArrayInt::New(); + const int aa[]={2,3,6,8,9}; + a->alloc(5,1); + std::copy(aa,aa+5,a->getPointer()); + DataArrayInt *b=DataArrayInt::New(); + const int bb[]={1,3,5,9,11}; + b->alloc(5,1); + std::copy(bb,bb+5,b->getPointer()); + // + DataArrayInt *c=a->buildSubstraction(b); + CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents()); + const int expected1[3]={2,6,8}; + CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer())); + // + c->decrRef(); + b->decrRef(); + a->decrRef(); +} + +void MEDCouplingBasicsTest::testBuildOrthogonalField2() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + DataArrayInt *d1=DataArrayInt::New(); + DataArrayInt *d2=DataArrayInt::New(); + DataArrayInt *d3=DataArrayInt::New(); + DataArrayInt *d4=DataArrayInt::New(); + MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4); + // + MEDCouplingFieldDouble *f1=m1->buildOrthogonalField(); + DataArrayDouble *da1=f1->getArray(); + CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples()); + // + const double expected1[26]={-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.}; + for(int i=0;i<26;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14); + // + f1->decrRef(); + m1->decrRef(); + d1->decrRef(); + d2->decrRef(); + d3->decrRef(); + d4->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testUMInsertNextCell1() +{ + double targetCoords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); + targetMesh->allocateCells(5); + CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception); + targetMesh->setMeshDimension(2); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn); + CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT0,1,targetConn),INTERP_KERNEL::Exception); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14); + targetMesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(9,2); + std::copy(targetCoords,targetCoords+18,myCoords->getPointer()); + targetMesh->setCoords(myCoords); + myCoords->decrRef(); + targetMesh->checkCoherency(); + targetMesh->decrRef(); +} + +void MEDCouplingBasicsTest::testFieldOperatorDivDiffComp1() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + DataArrayInt *d1=DataArrayInt::New(); + DataArrayInt *d2=DataArrayInt::New(); + DataArrayInt *d3=DataArrayInt::New(); + DataArrayInt *d4=DataArrayInt::New(); + MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4); + // + MEDCouplingFieldDouble *f1=m1->buildOrthogonalField(); + const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.}; + DataArrayDouble *arr=DataArrayDouble::New(); + arr->alloc(13,1); + std::copy(arr1,arr1+13,arr->getPointer()); + MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS); + f2->setArray(arr); + f2->setMesh(m1); + f2->checkCoherency(); + // + MEDCouplingFieldDouble *f3=(*f1)/(*f2); + CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception); + f3->checkCoherency(); + (*f1)/=(*f2); + CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10)); + CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception); + const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0}; + for(int i=0;i<26;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10); + // + f3->decrRef(); + f2->decrRef(); + arr->decrRef(); + f1->decrRef(); + m1->decrRef(); + d1->decrRef(); + d2->decrRef(); + d3->decrRef(); + d4->decrRef(); + m->decrRef(); +} + +void MEDCouplingBasicsTest::testDARearrange1() +{ + DataArrayInt *da1=DataArrayInt::New(); + da1->alloc(12,1); + da1->iota(0); + const int *ptr=da1->getConstPointer(); + // + CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples()); + da1->rearrange(4); + CPPUNIT_ASSERT(ptr==da1->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i)); + // + da1->rearrange(6); + CPPUNIT_ASSERT(ptr==da1->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i)); + // + CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception); + // + da1->rearrange(12); + CPPUNIT_ASSERT(ptr==da1->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i)); + // + da1->rearrange(3); + CPPUNIT_ASSERT(ptr==da1->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i)); + //double + DataArrayDouble *da2=da1->convertToDblArr(); + da1->decrRef(); + const double *ptr2=da2->getConstPointer(); + // + CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples()); + da2->rearrange(4); + CPPUNIT_ASSERT(ptr2==da2->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14); + // + da2->rearrange(6); + CPPUNIT_ASSERT(ptr2==da2->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14); + // + CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception); + // + da2->rearrange(1); + CPPUNIT_ASSERT(ptr2==da2->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14); + // + da2->rearrange(3); + CPPUNIT_ASSERT(ptr2==da2->getConstPointer()); + CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14); + da2->decrRef(); +} + +void MEDCouplingBasicsTest::testGetDifferentValues1() +{ + DataArrayInt *da1=DataArrayInt::New(); + const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2}; + da1->alloc(4,3); + std::copy(arr,arr+12,da1->getPointer()); + std::set s=da1->getDifferentValues(); + const int expected1[4]={1,2,3,5}; + CPPUNIT_ASSERT_EQUAL(4,(int)s.size()); + CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s.begin())); + da1->decrRef(); +} + diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/MEDCoupling.i similarity index 72% rename from src/MEDCoupling_Swig/libMEDCoupling_Swig.i rename to src/MEDCoupling_Swig/MEDCoupling.i index 65112f642..57fd23951 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -%module libMEDCoupling_Swig +%module MEDCoupling #define MEDCOUPLING_EXPORT @@ -32,8 +32,11 @@ #include "MEDCouplingField.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingGaussLocalization.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "MEDCouplingTypemaps.i" +#include "InterpKernelAutoPtr.hxx" + using namespace ParaMEDMEM; using namespace INTERP_KERNEL; %} @@ -61,7 +64,10 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingField::buildMeasureField; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::getArray; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::getEndArray; %newobject ParaMEDMEM::MEDCouplingFieldDouble::mergeFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::meldFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::doublyContractedProduct; %newobject ParaMEDMEM::MEDCouplingFieldDouble::determinant; %newobject ParaMEDMEM::MEDCouplingFieldDouble::eigenValues; @@ -88,15 +94,17 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::operator/; %newobject ParaMEDMEM::MEDCouplingFieldDouble::clone; %newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::deepCpy; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis; %newobject ParaMEDMEM::DataArrayInt::New; %newobject ParaMEDMEM::DataArrayInt::convertToDblArr; -%newobject ParaMEDMEM::DataArrayInt::deepCopy; +%newobject ParaMEDMEM::DataArrayInt::deepCpy; %newobject ParaMEDMEM::DataArrayInt::performCpy; %newobject ParaMEDMEM::DataArrayInt::substr; %newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents; %newobject ParaMEDMEM::DataArrayInt::keepSelectedComponents; %newobject ParaMEDMEM::DataArrayInt::selectByTupleId; +%newobject ParaMEDMEM::DataArrayInt::selectByTupleIdSafe; %newobject ParaMEDMEM::DataArrayInt::renumber; %newobject ParaMEDMEM::DataArrayInt::renumberR; %newobject ParaMEDMEM::DataArrayInt::renumberAndReduce; @@ -105,13 +113,20 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::getIdsEqual; %newobject ParaMEDMEM::DataArrayInt::getIdsEqualList; %newobject ParaMEDMEM::DataArrayInt::aggregate; +%newobject ParaMEDMEM::DataArrayInt::meld; %newobject ParaMEDMEM::DataArrayInt::fromNoInterlace; %newobject ParaMEDMEM::DataArrayInt::toNoInterlace; +%newobject ParaMEDMEM::DataArrayInt::buildComplement; +%newobject ParaMEDMEM::DataArrayInt::buildUnion; +%newobject ParaMEDMEM::DataArrayInt::buildSubstraction; +%newobject ParaMEDMEM::DataArrayInt::buildIntersection; +%newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; %newobject ParaMEDMEM::DataArrayDouble::New; %newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; -%newobject ParaMEDMEM::DataArrayDouble::deepCopy; +%newobject ParaMEDMEM::DataArrayDouble::deepCpy; %newobject ParaMEDMEM::DataArrayDouble::performCpy; %newobject ParaMEDMEM::DataArrayDouble::aggregate; +%newobject ParaMEDMEM::DataArrayDouble::meld; %newobject ParaMEDMEM::DataArrayDouble::dot; %newobject ParaMEDMEM::DataArrayDouble::crossProduct; %newobject ParaMEDMEM::DataArrayDouble::add; @@ -123,6 +138,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::keepSelectedComponents; %newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; %newobject ParaMEDMEM::DataArrayDouble::selectByTupleId; +%newobject ParaMEDMEM::DataArrayDouble::selectByTupleIdSafe; %newobject ParaMEDMEM::DataArrayDouble::applyFunc; %newobject ParaMEDMEM::DataArrayDouble::doublyContractedProduct; %newobject ParaMEDMEM::DataArrayDouble::determinant; @@ -149,14 +165,20 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingMesh::fillFromAnalytic; %newobject ParaMEDMEM::MEDCouplingMesh::getMeasureField; %newobject ParaMEDMEM::MEDCouplingMesh::simplexize; +%newobject ParaMEDMEM::MEDCouplingMesh::buildUnstructured; %newobject ParaMEDMEM::MEDCouplingPointSet::zipCoordsTraducer; %newobject ParaMEDMEM::MEDCouplingPointSet::buildBoundaryMesh; +%newobject ParaMEDMEM::MEDCouplingPointSet::mergeNodesArray; +%newobject ParaMEDMEM::MEDCouplingPointSet::buildInstanceFromMeshType; %newobject ParaMEDMEM::MEDCouplingUMesh::New; +%newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivity; +%newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex; %newobject ParaMEDMEM::MEDCouplingUMesh::clone; %newobject ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity; -%newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMeshFromThis; +%newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMesh; %newobject ParaMEDMEM::MEDCouplingUMesh::mergeUMeshes; +%newobject ParaMEDMEM::MEDCouplingUMesh::mergeUMeshesOnSameCoords; %newobject ParaMEDMEM::MEDCouplingUMesh::buildNewNumberingFromCommNodesFrmt; %newobject ParaMEDMEM::MEDCouplingUMesh::rearrange2ConsecutiveCellTypes; %newobject ParaMEDMEM::MEDCouplingUMesh::convertCellArrayPerGeoType; @@ -169,7 +191,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New; %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh; %newobject ParaMEDMEM::MEDCouplingCMesh::New; -%newobject ParaMEDMEM::MEDCouplingCMesh::buildUnstructured; +%newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt; %feature("unref") DataArrayDouble "$this->decrRef();" %feature("unref") MEDCouplingPointSet "$this->decrRef();" %feature("unref") MEDCouplingMesh "$this->decrRef();" @@ -218,6 +240,7 @@ namespace ParaMEDMEM class DataArrayInt; class DataArrayDouble; + class MEDCouplingUMesh; class MEDCouplingFieldDouble; class MEDCouplingMesh : public RefCountObject, public TimeLabel @@ -225,31 +248,32 @@ namespace ParaMEDMEM public: void setName(const char *name) { _name=name; } const char *getName() const { return _name.c_str(); } - virtual MEDCouplingMeshType getType() const = 0; - bool isStructured() const; - virtual bool isEqual(const MEDCouplingMesh *other, double prec) const; - virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const = 0; + virtual MEDCouplingMeshType getType() const throw(INTERP_KERNEL::Exception) = 0; + bool isStructured() const throw(INTERP_KERNEL::Exception); + virtual bool isEqual(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception); + virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception) = 0; virtual void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; virtual int getNumberOfCells() const throw(INTERP_KERNEL::Exception) = 0; virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception) = 0; virtual int getSpaceDimension() const throw(INTERP_KERNEL::Exception) = 0; virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception) = 0; - virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; - virtual DataArrayDouble *getBarycenterAndOwner() const = 0; - virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0; - virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; + virtual DataArrayDouble *getCoordinatesAndOwner() const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayDouble *getBarycenterAndOwner() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) = 0; + virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception) = 0; virtual std::string simpleRepr() const = 0; virtual std::string advancedRepr() const = 0; // tools - virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; - virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0; + virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception) = 0; + virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); - virtual MEDCouplingFieldDouble *buildOrthogonalField() const = 0; + virtual MEDCouplingFieldDouble *buildOrthogonalField() const throw(INTERP_KERNEL::Exception) = 0; + virtual MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception) = 0; - virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const; + virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); - static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); + static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const @@ -257,7 +281,7 @@ namespace ParaMEDMEM return self->simpleRepr(); } - int getCellContainingPoint(PyObject *p, double eps) const + int getCellContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception) { int sz; double *pos=convertPyToNewDblArr2(p,&sz); @@ -269,9 +293,8 @@ namespace ParaMEDMEM void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); self->renumberCells(tmp,check); - delete [] tmp; } PyObject *checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec) const throw(INTERP_KERNEL::Exception) @@ -283,29 +306,28 @@ namespace ParaMEDMEM PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(nodeCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, nodeCor?SWIG_POINTER_OWN | 0:0 )); return res; } - DataArrayInt *getCellIdsFullyIncludedInNodeIds(PyObject *li) const + DataArrayInt *getCellIdsFullyIncludedInNodeIds(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); DataArrayInt *ret=self->getCellIdsFullyIncludedInNodeIds(tmp,tmp+size); - delete [] tmp; return ret; } - PyObject *getNodeIdsOfCell(int cellId) const + PyObject *getNodeIdsOfCell(int cellId) const throw(INTERP_KERNEL::Exception) { std::vector conn; self->getNodeIdsOfCell(cellId,conn); return convertIntArrToPyList2(conn); } - PyObject *getCoordinatesOfNode(int nodeId) const + PyObject *getCoordinatesOfNode(int nodeId) const throw(INTERP_KERNEL::Exception) { std::vector coo; self->getCoordinatesOfNode(nodeId,coo); return convertDblArrToPyList2(coo); } - void scale(PyObject *point, double factor) + void scale(PyObject *point, double factor) throw(INTERP_KERNEL::Exception) { int sz; double *p=convertPyToNewDblArr2(point,&sz); @@ -323,19 +345,18 @@ namespace ParaMEDMEM return ret; } - PyObject *buildPart(PyObject *li) const + PyObject *buildPart(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); MEDCouplingMesh *ret=self->buildPart(tmp,tmp+size); - delete [] tmp; return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *buildPartAndReduceNodes(PyObject *li) const + PyObject *buildPartAndReduceNodes(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); DataArrayInt *arr=0; MEDCouplingMesh *ret=self->buildPartAndReduceNodes(tmp,tmp+size,arr); PyObject *res = PyList_New(2); @@ -346,26 +367,23 @@ namespace ParaMEDMEM return res; } - void translate(PyObject *vector) + void translate(PyObject *vector) throw(INTERP_KERNEL::Exception) { int sz; - double *v=convertPyToNewDblArr2(vector,&sz); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vector,&sz); self->translate(v); - delete [] v; } - void rotate(PyObject *center, PyObject *vector, double alpha) + void rotate(PyObject *center, PyObject *vector, double alpha) throw(INTERP_KERNEL::Exception) { int sz; - double *c=convertPyToNewDblArr2(center,&sz); + INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); if(!c) return ; - double *v=convertPyToNewDblArr2(vector,&sz); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vector,&sz); if(!v) - { delete [] c; return ; } + { return ; } self->rotate(c,v,alpha); - delete [] c; - delete [] v; } } }; @@ -383,26 +401,26 @@ namespace ParaMEDMEM { public: void updateTime(); - void setCoords(DataArrayDouble *coords); - DataArrayDouble *getCoordinatesAndOwner() const; - bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; - void zipCoords(); - double getCaracteristicDimension() const; + void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + DataArrayDouble *getCoordinatesAndOwner() const throw(INTERP_KERNEL::Exception); + bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const throw(INTERP_KERNEL::Exception); + void zipCoords() throw(INTERP_KERNEL::Exception); + double getCaracteristicDimension() const throw(INTERP_KERNEL::Exception); void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception); void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) = 0; - static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2); - static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); - virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; - virtual bool isEmptyMesh(const std::vector& tinyInfo) const = 0; + static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception); + static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type) throw(INTERP_KERNEL::Exception); + virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const throw(INTERP_KERNEL::Exception) = 0; + virtual bool isEmptyMesh(const std::vector& tinyInfo) const throw(INTERP_KERNEL::Exception) = 0; //! size of returned tinyInfo must be always the same. - void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; - void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; - void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const throw(INTERP_KERNEL::Exception); + void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const throw(INTERP_KERNEL::Exception); + void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const throw(INTERP_KERNEL::Exception); void unserialization(const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, - const std::vector& littleStrings); - virtual void giveElemsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) = 0; - virtual DataArrayInt *zipCoordsTraducer() = 0; + const std::vector& littleStrings) throw(INTERP_KERNEL::Exception); + virtual void giveElemsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception) = 0; %extend { std::string __str__() const @@ -410,7 +428,7 @@ namespace ParaMEDMEM return self->simpleRepr(); } - PyObject *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex) const + PyObject *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex) const throw(INTERP_KERNEL::Exception) { int newNbOfNodes; DataArrayInt *ret0=self->buildNewNumberingFromCommonNodesFormat(comm,commIndex,newNbOfNodes); @@ -420,7 +438,7 @@ namespace ParaMEDMEM return res; } - PyObject *findCommonNodes(int limitNodeId, double prec) const + PyObject *findCommonNodes(int limitNodeId, double prec) const throw(INTERP_KERNEL::Exception) { DataArrayInt *comm, *commIndex; self->findCommonNodes(limitNodeId,prec,comm,commIndex); @@ -430,48 +448,50 @@ namespace ParaMEDMEM return res; } - PyObject *getCoords() const + PyObject *getCoords() const throw(INTERP_KERNEL::Exception) { DataArrayDouble *ret1=self->getCoords(); ret1->incrRef(); return SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,SWIG_POINTER_OWN | 0); } - PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords) const + PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+size,keepCoords); - delete [] tmp; return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const + PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); - MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+size,fullyIn); - delete [] tmp; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,(int *)tmp+size,fullyIn); return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const + PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); - MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+size,fullyIn); - delete [] tmp; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,(int *)tmp+size,fullyIn); return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *findBoundaryNodes() const + PyObject *findBoundaryNodes() const throw(INTERP_KERNEL::Exception) { std::vector nodes; self->findBoundaryNodes(nodes); return convertIntArrToPyList2(nodes); } - void renumberNodes(PyObject *li, int newNbOfNodes) + void renumberNodes(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); self->renumberNodes(tmp,newNbOfNodes); - delete [] tmp; + } + void renumberNodes2(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + self->renumberNodes2(tmp,newNbOfNodes); } PyObject *findNodesOnPlane(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) { @@ -533,7 +553,7 @@ namespace ParaMEDMEM return ret; } - PyObject *giveElemsInBoundingBox(PyObject *bbox, double eps) + PyObject *giveElemsInBoundingBox(PyObject *bbox, double eps) throw(INTERP_KERNEL::Exception) { std::vector elems; int size; @@ -543,7 +563,7 @@ namespace ParaMEDMEM return convertIntArrToPyList2(elems); } - static void rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) + static void rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { int sz; double *c=convertPyToNewDblArr2(center,&sz); @@ -554,7 +574,7 @@ namespace ParaMEDMEM delete [] coo; delete [] c; } - static void rotate3DAlg(PyObject *center, PyObject *vect, double angle, int nbNodes, PyObject *coords) + static void rotate3DAlg(PyObject *center, PyObject *vect, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { int sz,sz2; double *c=convertPyToNewDblArr2(center,&sz); @@ -578,26 +598,24 @@ namespace ParaMEDMEM void updateTime(); void checkCoherency() const throw(INTERP_KERNEL::Exception); void setMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); - void allocateCells(int nbOfCells); - void finishInsertingCells(); - void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); - DataArrayInt *getNodalConnectivity() const; - DataArrayInt *getNodalConnectivityIndex() const; - INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; - int getNumberOfNodesInCell(int cellId) const; - int getMeshLength() const; - void computeTypes(); - std::string reprConnectivityOfThis() const; + void allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception); + void finishInsertingCells() throw(INTERP_KERNEL::Exception); + void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true) throw(INTERP_KERNEL::Exception); + INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); + int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); + int getMeshLength() const throw(INTERP_KERNEL::Exception); + void computeTypes() throw(INTERP_KERNEL::Exception); + std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); //tools - bool checkConsecutiveCellTypes() const; - DataArrayInt *rearrange2ConsecutiveCellTypes(); + bool checkConsecutiveCellTypes() const throw(INTERP_KERNEL::Exception); + DataArrayInt *rearrange2ConsecutiveCellTypes() throw(INTERP_KERNEL::Exception); DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception); - DataArrayInt *zipConnectivityTraducer(int compType); - void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const; - MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; + DataArrayInt *zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception); + void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); void orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Exception); - bool isPresenceOfQuadratic() const; - MEDCouplingFieldDouble *buildDirectionVectorField() const; + bool isPresenceOfQuadratic() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *buildDirectionVectorField() const throw(INTERP_KERNEL::Exception); bool isContiguous1D() const throw(INTERP_KERNEL::Exception); void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); void convertDegeneratedCells() throw(INTERP_KERNEL::Exception); @@ -606,19 +624,34 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getAspectRatioField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getWarpField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *mergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const { return self->simpleRepr(); } - void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) + void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception) { int sz; - int *tmp=convertPyToNewIntArr2(li,&sz); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&sz); self->insertNextCell(type,size,tmp); - delete [] tmp; } - PyObject *getAllTypes() const + DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret=self->getNodalConnectivity(); + if(ret) + ret->incrRef(); + return ret; + } + DataArrayInt *getNodalConnectivityIndex() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret=self->getNodalConnectivityIndex(); + if(ret) + ret->incrRef(); + return ret; + } + PyObject *getAllTypes() const throw(INTERP_KERNEL::Exception) { std::set result=self->getAllTypes(); std::set::const_iterator iL=result.begin(); @@ -627,7 +660,7 @@ namespace ParaMEDMEM PyList_SetItem(res,i,PyInt_FromLong(*iL)); return res; } - PyObject *mergeNodes(double precision) + PyObject *mergeNodes(double precision) throw(INTERP_KERNEL::Exception) { bool ret1; int ret2; @@ -638,14 +671,25 @@ namespace ParaMEDMEM PyList_SetItem(res,2,SWIG_From_int(ret2)); return res; } - PyObject *checkButterflyCells() + PyObject *mergeNodes2(double precision) throw(INTERP_KERNEL::Exception) + { + bool ret1; + int ret2; + DataArrayInt *ret0=self->mergeNodes2(precision,ret1,ret2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_bool(ret1)); + PyList_SetItem(res,2,SWIG_From_int(ret2)); + return res; + } + PyObject *checkButterflyCells() throw(INTERP_KERNEL::Exception) { std::vector cells; self->checkButterflyCells(cells); return convertIntArrToPyList2(cells); } - PyObject *splitByType() const + PyObject *splitByType() const throw(INTERP_KERNEL::Exception) { std::vector ms=self->splitByType(); int sz=ms.size(); @@ -655,7 +699,7 @@ namespace ParaMEDMEM return ret; } - PyObject *keepSpecifiedCells(INTERP_KERNEL::NormalizedCellType type, PyObject *ids) const + PyObject *keepSpecifiedCells(INTERP_KERNEL::NormalizedCellType type, PyObject *ids) const throw(INTERP_KERNEL::Exception) { std::vector idsPerGeoType; convertPyToNewIntArr3(ids,idsPerGeoType); @@ -663,25 +707,23 @@ namespace ParaMEDMEM return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ); } - bool checkConsecutiveCellTypesAndOrder(PyObject *li) const + bool checkConsecutiveCellTypesAndOrder(PyObject *li) const throw(INTERP_KERNEL::Exception) { int sz; - INTERP_KERNEL::NormalizedCellType *order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); bool ret=self->checkConsecutiveCellTypesAndOrder(order,order+sz); - delete [] order; return ret; } - DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(PyObject *li) const + DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(PyObject *li) const throw(INTERP_KERNEL::Exception) { int sz; - INTERP_KERNEL::NormalizedCellType *order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); - DataArrayInt *ret=self->getRenumArrForConsecutiveCellTypesSpec(order,order+sz); - delete [] order; + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + DataArrayInt *ret=self->getRenumArrForConsecutiveCellTypesSpec(order,(INTERP_KERNEL::NormalizedCellType *)order+sz); return ret; } - PyObject *getCellsContainingPoints(PyObject *p, int nbOfPoints, double eps) const + PyObject *getCellsContainingPoints(PyObject *p, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception) { int sz; double *pos=convertPyToNewDblArr2(p,&sz); @@ -694,7 +736,7 @@ namespace ParaMEDMEM return ret; } - PyObject *getCellsContainingPoint(PyObject *p, double eps) const + PyObject *getCellsContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception) { int sz; double *pos=convertPyToNewDblArr2(p,&sz); @@ -729,7 +771,7 @@ namespace ParaMEDMEM return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - static PyObject *fuseUMeshesOnSameCoords(PyObject *ms, int compType) + static PyObject *fuseUMeshesOnSameCoords(PyObject *ms, int compType) throw(INTERP_KERNEL::Exception) { int sz; std::vector meshes; @@ -797,36 +839,74 @@ namespace ParaMEDMEM std::copy(pos,pos+3,vals+3); return convertDblArrToPyListOfTuple(vals,3,2); } + + static MEDCouplingUMesh *mergeUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecUMeshesCst(li,tmp); + return MEDCouplingUMesh::mergeUMeshes(tmp); + } + + PyObject *areCellsIncludedIn(const MEDCouplingUMesh *other, int compType) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1; + bool ret0=self->areCellsIncludedIn(other,compType,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *buildDescendingConnectivity() const throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); + MEDCouplingUMesh *m=self->buildDescendingConnectivity(d0,d1,d2,d3); + PyObject *ret=PyTuple_New(5); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + d0->incrRef(); + d1->incrRef(); + d2->incrRef(); + d3->incrRef(); + return ret; + } } - void convertToPolyTypes(const std::vector& cellIdsToConvert); - void unPolyze(); - MEDCouplingUMesh *buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy); - static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + void convertToPolyTypes(const std::vector& cellIdsToConvert) throw(INTERP_KERNEL::Exception); + void unPolyze() throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy) throw(INTERP_KERNEL::Exception); }; class MEDCouplingExtrudedMesh : public ParaMEDMEM::MEDCouplingMesh { public: static MEDCouplingExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *build3DUnstructuredMesh() const; + MEDCouplingUMesh *build3DUnstructuredMesh() const throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const { return self->simpleRepr(); } - PyObject *getMesh2D() const + PyObject *getMesh2D() const throw(INTERP_KERNEL::Exception) { MEDCouplingUMesh *ret=self->getMesh2D(); ret->incrRef(); return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *getMesh1D() const + PyObject *getMesh1D() const throw(INTERP_KERNEL::Exception) { MEDCouplingUMesh *ret=self->getMesh1D(); ret->incrRef(); return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - PyObject *getMesh3DIds() const + PyObject *getMesh3DIds() const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret=self->getMesh3DIds(); ret->incrRef(); @@ -841,14 +921,20 @@ namespace ParaMEDMEM static MEDCouplingCMesh *New(); void setCoords(DataArrayDouble *coordsX, DataArrayDouble *coordsY=0, - DataArrayDouble *coordsZ=0); + DataArrayDouble *coordsZ=0) throw(INTERP_KERNEL::Exception); void setCoordsAt(int i, DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildUnstructured() const; %extend { std::string __str__() const { return self->simpleRepr(); } + DataArrayDouble *getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getCoordsAt(i); + if(ret) + ret->incrRef(); + return ret; + } } }; } @@ -877,20 +963,28 @@ namespace ParaMEDMEM return self->repr(); } - void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) + void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) throw(INTERP_KERNEL::Exception) { - int sz; - double *tmp=convertPyToNewDblArr2(li,&sz); + double *tmp=new double[nbOfTuples*nbOfElsPerTuple]; + try + { + fillArrayWithPyListDbl(li,tmp,nbOfTuples*nbOfElsPerTuple,0.); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple); } - PyObject *getValues() + PyObject *getValues() throw(INTERP_KERNEL::Exception) { const double *vals=self->getPointer(); return convertDblArrToPyList(vals,self->getNbOfElems()); } - PyObject *getValuesAsTuple() + PyObject *getValuesAsTuple() throw(INTERP_KERNEL::Exception) { const double *vals=self->getPointer(); int nbOfComp=self->getNumberOfComponents(); @@ -901,77 +995,74 @@ namespace ParaMEDMEM DataArrayDouble *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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 + DataArrayDouble *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); DataArrayDouble *ret=self->selectByTupleId(tmp,tmp+size); - delete [] tmp; + return ret; + } + + DataArrayDouble *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + DataArrayDouble *ret=self->selectByTupleIdSafe(tmp,tmp+size); return ret; } @@ -1046,6 +1137,28 @@ namespace ParaMEDMEM convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(a,tmp); } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new double[sz]; + self->getTuple(tupleId,tmp); + return convertDblArrToPyList(tmp,sz); + } + + static DataArrayDouble *aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecDataArrayDblCst(li,tmp); + return DataArrayDouble::aggregate(tmp); + } + + static DataArrayDouble *meld(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecDataArrayDblCst(li,tmp); + return DataArrayDouble::meld(tmp); + } }; %extend ParaMEDMEM::DataArrayInt @@ -1055,20 +1168,34 @@ namespace ParaMEDMEM return self->repr(); } - void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) + PyObject *getDifferentValues(bool val) const throw(INTERP_KERNEL::Exception) { - int size; - int *tmp=convertPyToNewIntArr2(li,&size); + std::set ret=self->getDifferentValues(); + return convertIntArrToPyList3(ret); + } + + void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) throw(INTERP_KERNEL::Exception) + { + int *tmp=new int[nbOfTuples*nbOfElsPerTuple]; + try + { + fillArrayWithPyListInt(li,tmp,nbOfTuples*nbOfElsPerTuple,0.); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple); } - PyObject *getValues() + PyObject *getValues() throw(INTERP_KERNEL::Exception) { const int *vals=self->getPointer(); return convertIntArrToPyList(vals,self->getNbOfElems()); } - PyObject *getValuesAsTuple() + PyObject *getValuesAsTuple() throw(INTERP_KERNEL::Exception) { const int *vals=self->getPointer(); int nbOfComp=self->getNumberOfComponents(); @@ -1076,7 +1203,7 @@ namespace ParaMEDMEM return convertIntArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); } - static PyObject *makePartition(PyObject *gps, int newNb) + static PyObject *makePartition(PyObject *gps, int newNb) throw(INTERP_KERNEL::Exception) { std::vector groups; std::vector< std::vector > fidsOfGroups; @@ -1095,77 +1222,74 @@ namespace ParaMEDMEM void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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); + INTERP_KERNEL::AutoPtr 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 + DataArrayInt *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); DataArrayInt *ret=self->selectByTupleId(tmp,tmp+size); - delete [] tmp; + return ret; + } + + DataArrayInt *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + DataArrayInt *ret=self->selectByTupleIdSafe(tmp,tmp+size); return ret; } @@ -1182,6 +1306,41 @@ namespace ParaMEDMEM convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(a,tmp); } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new int[sz]; + self->getTuple(tupleId,tmp); + return convertIntArrToPyList(tmp,sz); + } + + static DataArrayInt *meld(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecDataArrayIntCst(li,tmp); + return DataArrayInt::meld(tmp); + } + + PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=self->getMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } }; namespace ParaMEDMEM @@ -1190,39 +1349,39 @@ namespace ParaMEDMEM { public: virtual void checkCoherency() const throw(INTERP_KERNEL::Exception); - virtual bool areCompatibleForMerge(const MEDCouplingField *other) const; - virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; - virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; - void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); - void setName(const char *name); - const char *getDescription() const; - void setDescription(const char *desc); - const char *getName() const; - TypeOfField getTypeOfField() const; + virtual bool areCompatibleForMerge(const MEDCouplingField *other) const throw(INTERP_KERNEL::Exception); + virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); + virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); + void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); + void setName(const char *name) throw(INTERP_KERNEL::Exception); + const char *getDescription() const throw(INTERP_KERNEL::Exception); + void setDescription(const char *desc) throw(INTERP_KERNEL::Exception); + const char *getName() const throw(INTERP_KERNEL::Exception); + TypeOfField getTypeOfField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDiscretization *getDiscretization() const; + MEDCouplingFieldDiscretization *getDiscretization() const throw(INTERP_KERNEL::Exception); void setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); - void clearGaussLocalizations(); + void clearGaussLocalizations() throw(INTERP_KERNEL::Exception); MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); %extend { - PyObject *getMesh() const + PyObject *getMesh() const throw(INTERP_KERNEL::Exception) { MEDCouplingMesh *ret1=(MEDCouplingMesh *)self->getMesh(); - ret1->incrRef(); + if(ret1) + ret1->incrRef(); return convertMesh(ret1, SWIG_POINTER_OWN | 0 ); } - PyObject *buildSubMeshData(PyObject *li) const + PyObject *buildSubMeshData(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); DataArrayInt *ret1; MEDCouplingMesh *ret0=self->buildSubMeshData(tmp,tmp+size,ret1); - delete [] tmp; PyObject *res = PyList_New(2); PyList_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 )); PyList_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); @@ -1232,17 +1391,15 @@ namespace ParaMEDMEM const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); try { self->setGaussLocalizationOnCells(tmp,tmp+size,refCoo,gsCoo,wg); } catch(INTERP_KERNEL::Exception& e) { - delete [] tmp; throw e; } - delete [] tmp; } PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) { @@ -1263,30 +1420,30 @@ namespace ParaMEDMEM std::string advancedRepr() const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; - MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const; - TypeOfTimeDiscretization getTimeDiscretization() const; + MEDCouplingFieldDouble *deepCpy() const; + MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const throw(INTERP_KERNEL::Exception); + TypeOfTimeDiscretization getTimeDiscretization() const throw(INTERP_KERNEL::Exception); void checkCoherency() const throw(INTERP_KERNEL::Exception); - double getIJ(int tupleId, int compoId) const; - double getIJK(int cellId, int nodeIdInCell, int compoId) const; + double getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); + double getIJK(int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception); void setArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); void setEndArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); void setStartTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); void setEndTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); - DataArrayDouble *getArray() const throw(INTERP_KERNEL::Exception); - DataArrayDouble *getEndArray() const throw(INTERP_KERNEL::Exception); void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const throw(INTERP_KERNEL::Exception); int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); int getNumberOfValues() const throw(INTERP_KERNEL::Exception); - NatureOfField getNature() const { return _nature; } + NatureOfField getNature() const throw(INTERP_KERNEL::Exception); void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); - void setTimeTolerance(double val); - double getTimeTolerance() const; - void updateTime(); + void setTimeTolerance(double val) throw(INTERP_KERNEL::Exception); + double getTimeTolerance() const throw(INTERP_KERNEL::Exception); + void updateTime() throw(INTERP_KERNEL::Exception); 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 mergeNodes2(double eps) throw(INTERP_KERNEL::Exception); bool zipCoords() throw(INTERP_KERNEL::Exception); bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception); bool simplexize(int policy) throw(INTERP_KERNEL::Exception); @@ -1319,14 +1476,15 @@ namespace ParaMEDMEM DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); - static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const; - static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const; - static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const; - static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *meldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); @@ -1340,6 +1498,23 @@ namespace ParaMEDMEM { return self->simpleRepr(); } + + DataArrayDouble *getArray() const throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getArray(); + if(ret) + ret->incrRef(); + return ret; + } + + DataArrayDouble *getEndArray() const throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getEndArray(); + if(ret) + ret->incrRef(); + return ret; + } + PyObject *getValueOn(PyObject *sl) const throw(INTERP_KERNEL::Exception) { int sz; @@ -1382,7 +1557,7 @@ namespace ParaMEDMEM delete [] res; return ret; } - void setValues(PyObject *li) + void setValues(PyObject *li) throw(INTERP_KERNEL::Exception) { if(self->getArray()!=0) { @@ -1395,7 +1570,7 @@ namespace ParaMEDMEM else PyErr_SetString(PyExc_TypeError,"setValuesCpy : field must contain an array behind"); } - PyObject *getTime() + PyObject *getTime() throw(INTERP_KERNEL::Exception) { int tmp1,tmp2; double tmp0=self->getTime(tmp1,tmp2); @@ -1406,7 +1581,7 @@ namespace ParaMEDMEM return res; } - PyObject *getStartTime() + PyObject *getStartTime() throw(INTERP_KERNEL::Exception) { int tmp1,tmp2; double tmp0=self->getStartTime(tmp1,tmp2); @@ -1417,7 +1592,7 @@ namespace ParaMEDMEM return res; } - PyObject *getEndTime() + PyObject *getEndTime() throw(INTERP_KERNEL::Exception) { int tmp1,tmp2; double tmp0=self->getEndTime(tmp1,tmp2); @@ -1427,7 +1602,7 @@ namespace ParaMEDMEM PyList_SetItem(res,2,SWIG_From_int(tmp2)); return res; } - PyObject *accumulate() const + PyObject *accumulate() const throw(INTERP_KERNEL::Exception) { int sz=self->getNumberOfComponents(); double *tmp=new double[sz]; @@ -1436,7 +1611,7 @@ namespace ParaMEDMEM delete [] tmp; return ret; } - PyObject *integral(bool isWAbs) const + PyObject *integral(bool isWAbs) const throw(INTERP_KERNEL::Exception) { int sz=self->getNumberOfComponents(); double *tmp=new double[sz]; @@ -1467,38 +1642,34 @@ namespace ParaMEDMEM void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); try { self->renumberCells(tmp,check); } catch(INTERP_KERNEL::Exception& e) { - delete [] tmp; throw e; } - delete [] tmp; } void renumberNodes(PyObject *li) throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); try { self->renumberNodes(tmp); } catch(INTERP_KERNEL::Exception& e) { - delete [] tmp; throw e; } - delete [] tmp; } MEDCouplingFieldDouble *buildSubPart(PyObject *li) const throw(INTERP_KERNEL::Exception) { int size; - int *tmp=convertPyToNewIntArr2(li,&size); + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); MEDCouplingFieldDouble *ret=0; try { @@ -1506,10 +1677,8 @@ namespace ParaMEDMEM } catch(INTERP_KERNEL::Exception& e) { - delete [] tmp; throw e; } - delete [] tmp; return ret; } @@ -1546,6 +1715,13 @@ namespace ParaMEDMEM convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(f,tmp); } + + static MEDCouplingFieldDouble *mergeFields(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecFieldDblCst(li,tmp); + return MEDCouplingFieldDouble::mergeFields(tmp); + } } }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 25119adda..0139b3836 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDCoupling_Swig import * +from MEDCoupling import * import unittest from math import pi,e,sqrt from MEDCouplingDataForTest import MEDCouplingDataForTest @@ -182,13 +182,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): array=DataArrayDouble.New(); array.setValues(5*3*[7.],5,3); self.assertEqual(array.getIJ(3,2),7.); - array2=array.deepCopy(); + array2=array.deepCpy(); self.assertEqual(array2.getIJ(3,2),7.) # array3=DataArrayInt.New(); array3.setValues(5*3*[17],5,3); self.assertEqual(array3.getIJ(3,2),17); - array4=array3.deepCopy(); + array4=array3.deepCpy(); self.assertEqual(array4.getIJ(3,2),17); pass def testRevNodal(self): @@ -594,7 +594,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); # - arr2=arr.deepCopy(); + arr2=arr.deepCpy(); fieldOnCells2.setArray(arr2); self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); @@ -693,7 +693,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): center=[0.,0.,0.] vector=[0.,1.,0.] m2.rotate(center,vector,-pi/2.); - m3=m1.buildExtrudedMeshFromThis(m2,0); + m3=m1.buildExtrudedMesh(m2,0); # m4=MEDCouplingExtrudedMesh.New(m3,m1,0); self.assertEqual(15,m4.getNumberOfCells()); @@ -713,7 +713,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): #play with polygons and polyedrons cells=[2,3] m1.convertToPolyTypes(cells); - m3=m1.buildExtrudedMeshFromThis(m2,0); + m3=m1.buildExtrudedMesh(m2,0); self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(0)); self.assertEqual(NORM_PENTA6,m3.getTypeOfCell(1)); self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(2)); @@ -738,7 +738,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): center=[0.,0.,0.] vector=[0.,1.,0.] m2.rotate(center,vector,-pi/2.); - m3=m1.buildExtrudedMeshFromThis(m2,0); + m3=m1.buildExtrudedMesh(m2,0); expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4] rexpected1=[3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12] m3.renumberCells(expected1,False); @@ -1889,7 +1889,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): center=[0.,0.,0.] vector=[0.,1.,0.] m4.rotate(center,vector,-pi/2.); - m5=m3.buildExtrudedMeshFromThis(m4,0); + m5=m3.buildExtrudedMesh(m4,0); res1=m5.arePolyhedronsNotCorrectlyOriented(); self.assertEqual(15,len(res1)); m5.orientCorrectlyPolyhedrons(); @@ -2485,7 +2485,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): a1.fillWithZero(); a1.setInfoOnComponent(0,"c"); a1.setInfoOnComponent(1,"d"); - a2=a1.deepCopy(); + a2=a1.deepCpy(); a2.setInfoOnComponent(0,"e"); a2.setInfoOnComponent(1,"f"); f.setArray(a1); @@ -4542,6 +4542,11 @@ class MEDCouplingBasicsTest(unittest.TestCase): arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.] a1=DataArrayDouble.New(); a1.setValues(arr1,5,4); + expp=[21.,22.,23.,24.] + self.assertEqual(4,len(a1.getTuple(2))); + for i in xrange(4): + self.assertAlmostEqual(expp[i],a1.getTuple(2)[i],12) + pass a1.setInfoOnComponent(0,"aaaa"); a1.setInfoOnComponent(1,"bbbb"); a1.setInfoOnComponent(2,"cccc"); @@ -4561,6 +4566,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14); pass a3=a1.convertToIntArr(); + self.assertEqual([21,22,23,24],a3.getTuple(2)) a4=a3.keepSelectedComponents(arr2V); self.assertEqual(6,a4.getNumberOfComponents()); self.assertEqual(5,a4.getNumberOfTuples()); @@ -4985,7 +4991,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec"); h=g.fromPolarToCart(); f.setCoords(h); - i=c.buildExtrudedMeshFromThis(f,1); + i=c.buildExtrudedMesh(f,1); self.assertEqual(52,i.getNumberOfNodes()); tmp,tmp2,tmp3=i.mergeNodes(1e-9); self.assertTrue(tmp2); @@ -5033,7 +5039,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # center=[0.,0.] f.rotate(center,[],pi/3); - g=c.buildExtrudedMeshFromThis(f,0); + g=c.buildExtrudedMesh(f,0); g.checkCoherency(); expected1=[ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 ] f1=g.getMeasureField(True); @@ -5066,7 +5072,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec"); h=g.fromPolarToCart(); f.setCoords(h); - i=c.buildExtrudedMeshFromThis(f,1); + i=c.buildExtrudedMesh(f,1); self.assertEqual(52,i.getNumberOfNodes()); tmp,tmp2,tmp3=i.mergeNodes(1e-9); self.assertTrue(tmp2); @@ -5077,7 +5083,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): g2=h.applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec"); f.setCoords(g2); i.changeSpaceDimension(3); - i3=i.buildExtrudedMeshFromThis(f,1); + i3=i.buildExtrudedMesh(f,1); f2=i3.getMeasureField(True); tmp,tmp2,tmp3=i.mergeNodes(1e-9); self.assertTrue(tmp2); @@ -5165,6 +5171,531 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass # pass + + def testDAMeld1(self): + da1=DataArrayDouble.New(); + da1.alloc(7,2); + da2=DataArrayDouble.New(); + da2.alloc(7,1); + # + da1.fillWithValue(7.); + da2.iota(0.); + da3=da2.applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec"); + # + da1.setInfoOnComponent(0,"c0da1"); + da1.setInfoOnComponent(1,"c1da1"); + da3.setInfoOnComponent(0,"c0da3"); + da3.setInfoOnComponent(1,"c1da3"); + da3.setInfoOnComponent(2,"c2da3"); + # + da1C=da1.deepCpy(); + da1.meldWith(da3); + self.assertEqual(5,da1.getNumberOfComponents()); + self.assertEqual(7,da1.getNumberOfTuples()); + self.assertTrue(da1.getInfoOnComponent(0)=="c0da1"); + self.assertTrue(da1.getInfoOnComponent(1)=="c1da1"); + self.assertTrue(da1.getInfoOnComponent(2)=="c0da3"); + self.assertTrue(da1.getInfoOnComponent(3)=="c1da3"); + self.assertTrue(da1.getInfoOnComponent(4)=="c2da3"); + # + expected1=[7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.] + for i in xrange(35): + self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),10); + pass + # + dai1=da1C.convertToIntArr(); + dai3=da3.convertToIntArr(); + dai1.meldWith(dai3); + self.assertEqual(5,dai1.getNumberOfComponents()); + self.assertEqual(7,dai1.getNumberOfTuples()); + self.assertTrue(dai1.getInfoOnComponent(0)=="c0da1"); + self.assertTrue(dai1.getInfoOnComponent(1)=="c1da1"); + self.assertTrue(dai1.getInfoOnComponent(2)=="c0da3"); + self.assertTrue(dai1.getInfoOnComponent(3)=="c1da3"); + self.assertTrue(dai1.getInfoOnComponent(4)=="c2da3"); + for i in xrange(35): + self.assertEqual(int(expected1[i]),dai1.getIJ(0,i)); + pass + # test of static method DataArrayDouble::meld + da4=DataArrayDouble.meld(da1C,da3); + tmp=DataArrayDouble.meld([da1C,da3]); + self.assertTrue(da4.isEqual(tmp,1e-10)) + self.assertEqual(5,da4.getNumberOfComponents()); + self.assertEqual(7,da4.getNumberOfTuples()); + self.assertTrue(da4.getInfoOnComponent(0)=="c0da1"); + self.assertTrue(da4.getInfoOnComponent(1)=="c1da1"); + self.assertTrue(da4.getInfoOnComponent(2)=="c0da3"); + self.assertTrue(da4.getInfoOnComponent(3)=="c1da3"); + self.assertTrue(da4.getInfoOnComponent(4)=="c2da3"); + for i in xrange(35): + self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),10); + pass + # test of static method DataArrayInt::meld + dai1=da1C.convertToIntArr(); + dai4=DataArrayInt.meld(dai1,dai3); + tmp=DataArrayInt.meld([dai1,dai3]); + self.assertTrue(dai4.isEqual(tmp)) + self.assertEqual(5,dai4.getNumberOfComponents()); + self.assertEqual(7,dai4.getNumberOfTuples()); + self.assertTrue(dai4.getInfoOnComponent(0)=="c0da1"); + self.assertTrue(dai4.getInfoOnComponent(1)=="c1da1"); + self.assertTrue(dai4.getInfoOnComponent(2)=="c0da3"); + self.assertTrue(dai4.getInfoOnComponent(3)=="c1da3"); + self.assertTrue(dai4.getInfoOnComponent(4)=="c2da3"); + for i in xrange(35): + self.assertEqual(int(expected1[i]),dai4.getIJ(0,i)); + pass + pass + + def testFieldMeld1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setMesh(m); + da1=DataArrayDouble.New(); + arr1=[12.,23.,34.,45.,56.] + da1.setValues(arr1,5,1); + da1.setInfoOnComponent(0,"aaa"); + f1.setArray(da1); + f1.setTime(3.4,2,1); + f1.checkCoherency(); + # + f2=f1.deepCpy(); + f2.setMesh(f1.getMesh()); + f2.checkCoherency(); + f2.changeNbOfComponents(2,5.); + f2.assign(5.); + f2.getArray().setInfoOnComponent(0,"bbb"); + f2.getArray().setInfoOnComponent(1,"ccc"); + f2.checkCoherency(); + # + f3=MEDCouplingFieldDouble.meldFields(f2,f1); + f3.checkCoherency(); + self.assertEqual(5,f3.getNumberOfTuples()); + self.assertEqual(3,f3.getNumberOfComponents()); + self.assertTrue(f3.getArray().getInfoOnComponent(0)=="bbb"); + self.assertTrue(f3.getArray().getInfoOnComponent(1)=="ccc"); + self.assertTrue(f3.getArray().getInfoOnComponent(2)=="aaa"); + expected1=[5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.] + for i in xrange(15): + self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),12); + pass + time,dt,it=f3.getTime(); + self.assertAlmostEqual(3.4,time,14); + self.assertEqual(2,dt); + self.assertEqual(1,it); + # + f4=f2.buildNewTimeReprFromThis(NO_TIME,False); + f5=f1.buildNewTimeReprFromThis(NO_TIME,False); + f6=MEDCouplingFieldDouble.meldFields(f4,f5); + f6.checkCoherency(); + self.assertEqual(5,f6.getNumberOfTuples()); + self.assertEqual(3,f6.getNumberOfComponents()); + self.assertTrue(f6.getArray().getInfoOnComponent(0)=="bbb"); + self.assertTrue(f6.getArray().getInfoOnComponent(1)=="ccc"); + self.assertTrue(f6.getArray().getInfoOnComponent(2)=="aaa"); + for i in xrange(15): + self.assertAlmostEqual(expected1[i],f6.getIJ(0,i),12); + pass + # + pass + + def testMergeNodes2(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + vec=[0.002,0.] + m2.translate(vec); + # + m3=MEDCouplingUMesh.mergeUMeshes([m1,m2]); + da,b,newNbOfNodes=m3.mergeNodes2(0.01); + self.assertEqual(9,m3.getNumberOfNodes()); + expected1=[-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7] + for i in xrange(18): + self.assertAlmostEqual(expected1[i],m3.getCoords().getIJ(0,i),13); + pass + # + pass + + def testMergeField2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setMesh(m); + arr=DataArrayDouble.New(); + arr.alloc(5,2); + arr.fillWithValue(2.); + f1.setArray(arr); + f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f2.setMesh(m); + arr=DataArrayDouble.New(); + arr.alloc(5,2); + arr.fillWithValue(5.); + f2.setArray(arr); + f3=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f3.setMesh(m); + arr=DataArrayDouble.New(); + arr.alloc(5,2); + arr.fillWithValue(7.); + f3.setArray(arr); + # + f4=MEDCouplingFieldDouble.mergeFields([f1,f2,f3]); + self.assertEqual(15,f4.getMesh().getNumberOfCells()); + expected1=[2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.] + for i in xrange(30): + self.assertAlmostEqual(expected1[i],f4.getIJ(0,i),13); + pass + # + pass + + def testDAIBuildComplement1(self): + a=DataArrayInt.New(); + tab=[3,1,7,8] + a.setValues(tab,4,1); + b=a.buildComplement(12); + self.assertEqual(8,b.getNumberOfTuples()); + self.assertEqual(1,b.getNumberOfComponents()); + expected1=[0,2,4,5,6,9,10,11] + for i in xrange(8): + self.assertEqual(expected1[i],b.getIJ(0,i)); + pass + pass + + def testDAIBuildUnion1(self): + a=DataArrayInt.New(); + tab1=[3,1,7,8] + a.setValues(tab1,4,1); + c=DataArrayInt.New(); + tab2=[5,3,0,18,8] + c.setValues(tab2,5,1); + b=a.buildUnion(c); + self.assertEqual(7,b.getNumberOfTuples()); + self.assertEqual(1,b.getNumberOfComponents()); + expected1=[0,1,3,5,7,8,18] + for i in xrange(7): + self.assertEqual(expected1[i],b.getIJ(0,i)); + pass + pass + + def testDAIBuildIntersection1(self): + a=DataArrayInt.New(); + tab1=[3,1,7,8] + a.setValues(tab1,4,1); + c=DataArrayInt.New(); + tab2=[5,3,0,18,8] + c.setValues(tab2,5,1); + b=a.buildIntersection(c); + self.assertEqual(2,b.getNumberOfTuples()); + self.assertEqual(1,b.getNumberOfComponents()); + expected1=[3,8] + for i in xrange(2): + self.assertEqual(expected1[i],b.getIJ(0,i)); + pass + pass + + def testDAIDeltaShiftIndex1(self): + a=DataArrayInt.New(); + tab=[1,3,6,7,7,9,15] + a.setValues(tab,7,1); + b=a.deltaShiftIndex(); + self.assertEqual(6,b.getNumberOfTuples()); + self.assertEqual(1,b.getNumberOfComponents()); + expected1=[2,3,1,0,2,6] + for i in xrange(6): + self.assertEqual(expected1[i],b.getIJ(0,i)); + pass + pass + + def testDaDoubleSelectByTupleIdSafe1(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.selectByTupleIdSafe(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 + arr4=[4,-1,0,6,5] + self.assertRaises(Exception,a.selectByTupleIdSafe,arr4); + arr5=[4,2,0,6,7] + self.assertRaises(Exception,a.selectByTupleIdSafe,arr5); + # + 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.selectByTupleIdSafe(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 + self.assertRaises(Exception,c.selectByTupleIdSafe,arr4); + self.assertRaises(Exception,c.selectByTupleIdSafe,arr5); + pass + + def testAreCellsIncludedIn1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + pt=[1,3] + m2=m.buildPartOfMySelf(pt,True); + ret,tmp=m.areCellsIncludedIn(m2,0) + self.assertTrue(ret); + self.assertEqual(2,tmp.getNumberOfTuples()); + self.assertEqual(1,tmp.getNumberOfComponents()); + self.assertEqual(pt[0],tmp.getIJ(0,0)); + self.assertEqual(pt[1],tmp.getIJ(0,1)); + ret,tmp=m2.areCellsIncludedIn(m,0) + self.assertTrue(not ret); + pass + + def testSwigErrorProtection1(self): + m=MEDCouplingDataForTest.build3DTargetMesh_1(); + m.rotate([0.,0.,0.],[0.3,0.6,1.2],0.37) + m.rotate([0.,0.,0.],[0.3,6,1.2],0.37) + self.assertRaises(Exception,m.rotate,[0.,0.,0.],(0.3,6,"1.2"),0.37) + self.assertRaises(Exception,m.rotate,[0.,"0.",0.],[0.3,0.6,1.2],0.37) + self.assertRaises(Exception,m.rotate,[0.,0.,0.],[0.3,'0.6',1.2],0.37) + m2=m.buildPartOfMySelf([2,5],True) + m3=m.buildPartOfMySelf((2,5),True) + self.assertTrue(m2.isEqual(m3,1e-12)) + self.assertRaises(Exception,m.buildPartOfMySelf,[2,5.],True) + da1=m.getCoords().keepSelectedComponents([1]) + da2=m.getCoords().keepSelectedComponents((1,)) + self.assertTrue(da1.isEqual(da2,1e-12)) + self.assertRaises(Exception,m.getCoords().keepSelectedComponents,["1"]) + pass + + def testDAIBuildSubstraction1(self): + a=DataArrayInt.New() + aa=[2,3,6,8,9] + a.setValues(aa,5,1) + b=DataArrayInt.New() + bb=[1,3,5,9,11] + b.setValues(bb,5,1) + self.assertEqual([2,6,8],a.buildSubstraction(b).getValues()) + pass + + def testBuildOrthogonalField2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + d1=DataArrayInt.New(); + d2=DataArrayInt.New(); + d3=DataArrayInt.New(); + d4=DataArrayInt.New(); + m1=m.buildDescendingConnectivity(d1,d2,d3,d4); + # + f1=m1.buildOrthogonalField(); + da1=f1.getArray(); + self.assertEqual(2,da1.getNumberOfComponents()); + self.assertEqual(13,da1.getNumberOfTuples()); + # + expected1=[-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.]; + for i in xrange(26): + self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),14); + pass + pass + + def testSwigErrorProtection2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + coo=m.getCoords() + c=m.getNodalConnectivity() + ci=m.getNodalConnectivityIndex() + del m + self.assertEqual(2,coo.getNumberOfComponents()); + self.assertEqual(6,ci.getNumberOfTuples()); + self.assertEqual(23,c.getNumberOfTuples()); + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=m.getMeasureField(True) + c=f.getArray() + del f + self.assertEqual(1,c.getNumberOfComponents()); + m=MEDCouplingCMesh.New() + x=DataArrayDouble.New() + x.setValues([1.,2.,4.],3,1) + m.setCoordsAt(0,x) + del x + xx=m.getCoordsAt(0) + del m + self.assertEqual(3,xx.getNumberOfTuples()); + # + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=m.getMeasureField(True) + m2=f.getMesh() + del m + del f + self.assertEqual(5,m2.getNumberOfCells()); + pass + + def testUMInsertNextCell1(self): + targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ] + targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.allocateCells(5); + self.assertRaises(Exception,targetMesh.insertNextCell,NORM_QUAD4,4,targetConn[0:4]) + targetMesh.setMeshDimension(2); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]) + self.assertRaises(Exception,targetMesh.insertNextCell,NORM_TETRA4,4,targetConn[0:4]) + self.assertRaises(Exception,targetMesh.insertNextCell,NORM_SEG2,2,targetConn[0:2]) + self.assertRaises(Exception,targetMesh.insertNextCell,NORM_POINT0,1,targetConn[0:1]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]) + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,9,2); + targetMesh.setCoords(myCoords); + targetMesh.checkCoherency(); + pass + + def testFieldOperatorDivDiffComp1(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + m1,d0,d1,d2,d3=m.buildDescendingConnectivity(); + # + f1=m1.buildOrthogonalField(); + arr1=[2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.] + arr=DataArrayDouble.New(); + arr.setValues(arr1,13,1); + f2=MEDCouplingFieldDouble.New(ON_CELLS); + f2.setArray(arr); + f2.setMesh(m1); + f2.checkCoherency(); + # + f3=f1/f2; + self.assertRaises(Exception,f2.__div__,f1) + f3.checkCoherency(); + f1/=f2; + #self.assertRaises(Exception,f2.__idiv__,f1) # mem leaks + self.assertTrue(f1.isEqual(f3,1e-10,1e-10)); + expected1=[-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0] + for i in xrange(26): + self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10); + pass + pass + + def testDARearrange1(self): + da1=DataArrayInt.New(); + da1.alloc(12,1); + da1.iota(0); + # + self.assertEqual(12,da1.getNbOfElems()); + self.assertEqual(1,da1.getNumberOfComponents()); + self.assertEqual(12,da1.getNumberOfTuples()); + da1.rearrange(4); + self.assertEqual(12,da1.getNbOfElems()); + self.assertEqual(4,da1.getNumberOfComponents()); + self.assertEqual(3,da1.getNumberOfTuples()); + for i in xrange(12): + self.assertEqual(i,da1.getIJ(0,i)); + # + da1.rearrange(6); + self.assertEqual(12,da1.getNbOfElems()); + self.assertEqual(6,da1.getNumberOfComponents()); + self.assertEqual(2,da1.getNumberOfTuples()); + for i in xrange(12): + self.assertEqual(i,da1.getIJ(0,i)); + # + self.assertRaises(da1.rearrange(7),Exception); + # + da1.rearrange(12); + self.assertEqual(12,da1.getNbOfElems()); + self.assertEqual(12,da1.getNumberOfComponents()); + self.assertEqual(1,da1.getNumberOfTuples()); + for i in xrange(12): + self.assertEqual(i,da1.getIJ(0,i)); + # + da1.rearrange(3); + self.assertEqual(12,da1.getNbOfElems()); + self.assertEqual(3,da1.getNumberOfComponents()); + self.assertEqual(4,da1.getNumberOfTuples()); + for i in xrange(12): + self.assertEqual(i,da1.getIJ(0,i)); + #double + da2=da1.convertToDblArr(); + # + self.assertEqual(12,da2.getNbOfElems()); + self.assertEqual(3,da2.getNumberOfComponents()); + self.assertEqual(4,da2.getNumberOfTuples()); + da2.rearrange(4); + self.assertEqual(12,da2.getNbOfElems()); + self.assertEqual(4,da2.getNumberOfComponents()); + self.assertEqual(3,da2.getNumberOfTuples()); + for i in xrange(12): + self.assertAlmostEqual(float(i),da2.getIJ(0,i),14); + # + da2.rearrange(6); + self.assertEqual(12,da2.getNbOfElems()); + self.assertEqual(6,da2.getNumberOfComponents()); + self.assertEqual(2,da2.getNumberOfTuples()); + for i in xrange(12): + self.assertAlmostEqual(float(i),da2.getIJ(0,i),14); + # + self.assertRaises(da2.rearrange(7),Exception); + # + da2.rearrange(1); + self.assertTrue(ptr2==da2.getConstPointer()); + self.assertEqual(12,da2.getNbOfElems()); + self.assertEqual(1,da2.getNumberOfComponents()); + self.assertEqual(12,da2.getNumberOfTuples()); + for i in xrange(12): + self.assertAlmostEqual(float(i),da2.getIJ(0,i),14); + # + da2.rearrange(3); + self.assertEqual(12,da2.getNbOfElems()); + self.assertEqual(3,da2.getNumberOfComponents()); + self.assertEqual(4,da2.getNumberOfTuples()); + for i in xrange(12): + self.assertAlmostEqual(float(i),da2.getIJ(0,i),14); + pass + + def testDARearrange1(self): + da1=DataArrayInt.New(); + arr=[1,2,3,2,2,3,5,1,5,5,2,2] + da1.setValues(arr,4,3); + s=da1.getDifferentValues(True);# API different from C++ because SWIG complains... + expected1=[1,2,3,5] + self.assertEqual(expected1,s); + pass + + def testSwigErrorProtection3(self): + da=DataArrayInt.New() + da.setValues([1,2,3,4],4,3) + self.assertEqual([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + da=DataArrayInt.New() + da.setValues((1,2,3,4,4,3),4,3) + self.assertEqual([1, 2, 3, 4, 4, 3, 0, 0, 0, 0, 0, 0],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + da.setValues(10*[1]+290*[2],4,3) + self.assertEqual(10*[1]+[2,2],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + # + da=DataArrayDouble.New() + da.setValues([1,2,3.,4],4,3) + self.assertEqual([1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + da=DataArrayDouble.New() + da.setValues((1,2,3,4.,4,3),4,3) + self.assertEqual([1., 2., 3., 4., 4., 3., 0., 0., 0., 0., 0., 0.],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + da.setValues(10*[1]+290*[2],4,3) + self.assertEqual(10*[1.]+[2.,2.],da.getValues()) + self.assertEqual(3,da.getNumberOfComponents()); + self.assertEqual(4,da.getNumberOfTuples()); + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index d152e2a4b..e00c447ea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDCoupling_Swig import * +from MEDCoupling import * class MEDCouplingDataForTest: def build2DTargetMesh_1(cls): diff --git a/src/MEDCoupling_Swig/libMEDCouplingRemapper_Swig.i b/src/MEDCoupling_Swig/MEDCouplingRemapper.i similarity index 95% rename from src/MEDCoupling_Swig/libMEDCouplingRemapper_Swig.i rename to src/MEDCoupling_Swig/MEDCouplingRemapper.i index b46f81984..ae383b88a 100644 --- a/src/MEDCoupling_Swig/libMEDCouplingRemapper_Swig.i +++ b/src/MEDCoupling_Swig/MEDCouplingRemapper.i @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -%module libMEDCouplingRemapper_Swig +%module MEDCouplingRemapper #define MEDCOUPLING_EXPORT #define INTERPKERNEL_EXPORT @@ -37,6 +37,6 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingRemapper::transferField; %newobject ParaMEDMEM::MEDCouplingRemapper::reverseTransferField; -%include "libMEDCoupling_Swig.i" +%include "MEDCoupling.i" %include "InterpolationOptions.hxx" %include "MEDCouplingRemapper.hxx" diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 4be38ae90..4f38166b5 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDCouplingRemapper_Swig import * +from MEDCouplingRemapper import * from math import * import unittest diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index d1af65ba8..42dcee277 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -21,7 +21,7 @@ #include #endif -static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner) +static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(dynamic_cast(mesh)) @@ -32,13 +32,14 @@ static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner); if(!ret) { - PyErr_SetString(PyExc_TypeError,"Not recognized type of mesh on downcast !"); - PyErr_Print(); + const char msg[]="Not recognized type of mesh on downcast !"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); } return ret; } -static PyObject *convertIntArrToPyList(const int *ptr, int size) +static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception) { #ifndef WITH_NUMPY2 PyObject *ret=PyList_New(size); @@ -53,7 +54,7 @@ static PyObject *convertIntArrToPyList(const int *ptr, int size) #endif } -static PyObject *convertIntArrToPyList2(const std::vector& v) +static PyObject *convertIntArrToPyList2(const std::vector& v) throw(INTERP_KERNEL::Exception) { #ifndef WITH_NUMPY2 int size=v.size(); @@ -69,7 +70,17 @@ static PyObject *convertIntArrToPyList2(const std::vector& v) #endif } -static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) +static PyObject *convertIntArrToPyList3(const std::set& v) throw(INTERP_KERNEL::Exception) +{ + int size=v.size(); + PyObject *ret=PyList_New(size); + std::set::const_iterator it=v.begin(); + for(int i=0;i& arr) +static void convertPyToNewIntArr3(PyObject *pyLi, std::vector& arr) throw(INTERP_KERNEL::Exception) { if(PyList_Check(pyLi)) { @@ -146,17 +179,38 @@ static void convertPyToNewIntArr3(PyObject *pyLi, std::vector& arr) } else { - PyErr_SetString(PyExc_TypeError,"list must contain integers only"); - PyErr_Print(); + const char msg[]="list must contain integers only"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); + } + } + } + else if(PyTuple_Check(pyLi)) + { + int size=PyTuple_Size(pyLi); + arr.resize(size); + for(int i=0;i& arr) } else { - PyErr_SetString(PyExc_TypeError,"convertPyToNewIntArr3 : not a list nor PyArray"); - PyErr_Print(); - return ; + const char msg[]="convertPyToNewIntArr3 : not a list nor PyArray"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); } #endif } } -static PyObject *convertDblArrToPyList(const double *ptr, int size) +static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + for(int i=0;i& v) +static PyObject *convertDblArrToPyList2(const std::vector& v) throw(INTERP_KERNEL::Exception) { int size=v.size(); PyObject *ret=PyList_New(size); @@ -193,7 +304,7 @@ static PyObject *convertDblArrToPyList2(const std::vector& v) return ret; } -static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) +static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception) { PyObject *ret=PyList_New(nbOfTuples); for(int i=0;i& v) +static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + for(int i=0;i& v) throw(INTERP_KERNEL::Exception) { if(PyList_Check(ms)) { @@ -250,9 +464,9 @@ void convertPyObjToVecUMeshes(PyObject *ms, std::vector(argp); v[i]=arg; @@ -260,12 +474,129 @@ void convertPyObjToVecUMeshes(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + const char msg[]="convertPyObjToVecUMeshesCst : not a list"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); + } +} + +void convertPyObjToVecDataArrayDblCst(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + const char msg[]="convertPyObjToVecDataArrayDblCst : not a list"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); + } +} + +void convertPyObjToVecFieldDblCst(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + const char msg[]="convertPyObjToVecFieldDblCst : not a list"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); + } +} + +void convertPyObjToVecDataArrayInt(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + const char msg[]="convertPyObjToVecDataArrayInt : not a list"; + PyErr_SetString(PyExc_TypeError,msg); + throw INTERP_KERNEL::Exception(msg); } } -void convertPyObjToVecDataArrayInt(PyObject *ms, std::vector& v) +void convertPyObjToVecDataArrayIntCst(PyObject *ms, std::vector& v) throw(INTERP_KERNEL::Exception) { if(PyList_Check(ms)) { @@ -278,9 +609,9 @@ void convertPyObjToVecDataArrayInt(PyObject *ms, std::vector(argp); v[i]=arg; @@ -288,7 +619,8 @@ void convertPyObjToVecDataArrayInt(PyObject *ms, std::vector + +using namespace ParaMEDMEM; + +MEDFileString::MEDFileString(int maxLgth):_max_lgth(maxLgth),_content(new char[maxLgth+1]) +{ + std::fill(_content,_content+maxLgth+1,'\0'); +} + +MEDFileString::~MEDFileString() +{ + delete [] _content; +} + +void MEDFileString::set(const char *s) throw(INTERP_KERNEL::Exception) +{ + if((int)strlen(s)>_max_lgth) + throw INTERP_KERNEL::Exception("Name is too long to be stored in MEDfile !"); + std::fill(_content,_content+_max_lgth+1,'\0'); + strcpy(_content,s); +} + +std::string MEDFileString::getRepr() const +{ + return std::string(_content); +} + diff --git a/src/MEDLoader/MEDFileBasis.hxx b/src/MEDLoader/MEDFileBasis.hxx new file mode 100644 index 000000000..6e5394691 --- /dev/null +++ b/src/MEDLoader/MEDFileBasis.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEBASIS_HXX__ +#define __MEDFILEBASIS_HXX__ + +#include "InterpKernelException.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + class MEDFileString + { + public: + MEDFileString(int maxLgth); + ~MEDFileString(); + void set(const char *s) throw(INTERP_KERNEL::Exception); + char *getPointer() { return _content; } + const char *getReprForWrite() const { return _content; } + std::string getRepr() const; + private: + int _max_lgth; + char *_content; + }; + + + class MEDFileMultiString + { + public: + MEDFileMultiString(int nbOfCompo, int maxLgthPerCompo); + ~MEDFileMultiString(); + void set(int compoId, const char *s); + const char *getReprForWrite() const; + std::vector getRepr() const; + std::string getReprPerComp(int compId) const; + private: + int _nb_of_comp; + int _max_lgth_per_comp; + char *_content; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx new file mode 100644 index 000000000..5e336bb1c --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -0,0 +1,666 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMesh.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoader.hxx" +#include "MEDLoaderBase.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" + +using namespace ParaMEDMEM; + +MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + +MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileUMesh(fileName,mName); +} + +MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + std::vector ms=MEDLoader::GetMeshNames(fileName); + if(ms.empty()) + { + std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return new MEDFileUMesh(fileName,ms.front().c_str()); +} + +MEDFileUMesh *MEDFileUMesh::New() +{ + return new MEDFileUMesh; +} + +MEDFileUMesh::MEDFileUMesh():_too_long_str(0) +{ +} + +MEDFileUMesh::MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) + try:_too_long_str(0) + { + MEDFileUtilities::CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + MEDFileUMeshL2 loaderl2; + loaderl2.loadAll(fid,MEDFileUMeshL2::getMeshIdFromName(fid,mName),mName); + int lev=loaderl2.getNumberOfLevels(); + _ms.resize(lev); + for(int i=0;i maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC); + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_TAILLE_NOM,maa,_too_long_str); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_TAILLE_DESC,desc,_too_long_str); + int spaceDim=coo?coo->getNumberOfComponents():0; + MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc); + MEDdimEspaceCr(fid,maa,spaceDim); + MEDFileUMeshL2::writeCoords(fid,maa,_coords,_fam_coords,_num_coords); + int mdim=getMeshDimension(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + (*it)->write(fid,maa,mdim); + MEDFileUMeshL2::writeFamiliesAndGrps(fid,maa,_families,_groups); + MEDfermer(fid); +} + +int MEDFileUMesh::getNumberOfNonEmptyLevels() const +{ + int ret=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + if(!(*it)->empty()) + ret++; + return ret; +} + +std::vector MEDFileUMesh::getNonEmptyLevels() const +{ + std::vector ret; + int lev=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + if(!(*it)->empty()) + ret.push_back(lev); + return ret; +} + +std::vector MEDFileUMesh::getNonEmptyLevelsExt() const +{ + std::vector ret0=getNonEmptyLevels(); + if((const DataArrayDouble *) _coords) + { + std::vector ret(ret0.size()+1); + ret[0]=1; + std::copy(ret0.begin(),ret0.end(),ret.begin()+1); + return ret; + } + return ret0; +} + +int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map::const_iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +std::vector MEDFileUMesh::getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds; + for(std::vector::const_iterator it=famNames.begin();it!=famNames.end();it++) + { + std::map::const_iterator it2=_families.find(*it); + if(it2==_families.end()) + { + std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + famIds.push_back((*it2).second); + } + return famIds; +} + +std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception) +{ + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + if((*it).second==id) + return (*it).first; + std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileUMesh::getMeshDimension() const +{ + int lev=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++) + if((const MEDFileUMeshSplitL1 *)(*it)!=0) + return (*it)->getMeshDimension()+lev; + throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !"); +} + +int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!((const DataArrayDouble *)_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !"); + return _coords->getNumberOfTuples(); + } + MEDCouplingUMesh *m=getMeshAtRank(meshDimRelToMaxExt,false); + return m->getNumberOfCells(); +} + +const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!((const DataArrayInt *)_fam_coords)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !"); + return _fam_coords; + } + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getFamilyField(); +} + +std::vector MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::const_iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return (*it).second; +} + +std::vector MEDFileUMesh::getGroupsNames() const +{ + std::vector ret(_groups.size()); + int i=0; + for(std::map >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++) + ret[i]=(*it).first; + return ret; +} + +std::vector MEDFileUMesh::getFamiliesNames() const +{ + std::vector ret(_families.size()); + int i=0; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++,i++) + ret[i]=(*it).first; + return ret; +} + +void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _groups.erase(it); +} + +void MEDFileUMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map::iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _families.erase(it); +} + +void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +{ + std::string oname(oldName); + std::map >::iterator it=_groups.find(oname); + std::vector grps=getGroupsNames(); + if(it==_groups.end()) + { + std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :"; + std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::string nname(newName); + it=_groups.find(nname); + if(it!=_groups.end()) + { + std::ostringstream oss; oss << "Such groupname \"" << newName << " already exists ! Kill it before !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::vector cpy=(*it).second; + _groups.erase(it); + _groups[newName]=cpy; +} + +void MEDFileUMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) +{ + std::string oname(oldName); + std::map::iterator it=_families.find(oname); + std::vector fams=getFamiliesNames(); + if(it==_families.end()) + { + std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::string nname(newName); + it=_families.find(nname); + if(it!=_families.end()) + { + std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + int cpy=(*it).second; + _families.erase(it); + _families[newName]=cpy; +} + +DataArrayDouble *MEDFileUMesh::getCoords() const +{ + MEDCouplingAutoRefCountObjectPtr tmp(_coords); + if((DataArrayDouble *)tmp) + { + tmp->incrRef(); + return tmp; + } + return 0; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMax, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + MEDCouplingUMesh *ret=getGroups(meshDimRelToMax,tmp,renum); + ret->setName(grp); + return ret; +} + +DataArrayInt *MEDFileUMesh::getGroupArr(int meshDimRelToMax, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + DataArrayInt *ret=getGroupsArr(meshDimRelToMax,tmp,renum); + ret->setName(grp); + return ret; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return getFamilies(meshDimRelToMax,fams2,renum); +} + +DataArrayInt *MEDFileUMesh::getGroupsArr(int meshDimRelToMax, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return getFamiliesArr(meshDimRelToMax,fams2,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + MEDCouplingUMesh *ret=getFamilies(meshDimRelToMax,tmp,renum); + ret->setName(fam); + return ret; +} + +DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMax, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + DataArrayInt *ret=getFamiliesArr(meshDimRelToMax,tmp,renum); + ret->setName(fam); + return ret; +} + +MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds=getFamiliesIds(fams); + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); + return l1->getFamilyPart(famIds,renum); +} + +DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMax, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds=getFamiliesIds(fams); + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); + return l1->getFamilyPartArr(famIds,renum); +} + +DataArrayInt *MEDFileUMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + DataArrayInt *ret=getNodeGroupsArr(tmp,renum); + ret->setName(grp); + return ret; +} + +DataArrayInt *MEDFileUMesh::getNodeGroupsArr(const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return getNodeFamiliesArr(fams2,renum); +} + +DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + DataArrayInt *ret=getNodeFamiliesArr(tmp,renum); + ret->setName(fam); + return ret; +} + +DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +{ + std::vector famIds=getFamiliesIds(fams); + DataArrayInt *da=_fam_coords->getIdsEqualList(famIds); + if(renum) + return MEDFileUMeshSplitL1::renumber(_num_coords,da); + return da; +} + +MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception) +{ + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); + return l1->getWholeMesh(renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getRank0Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(0,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-1,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-2,renum); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-3,renum); +} + +const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + int tracucedRk=-meshDimRelToMax; + if(tracucedRk>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); + if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[tracucedRk]; +} + +MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMax) throw(INTERP_KERNEL::Exception) +{ + int tracucedRk=-meshDimRelToMax; + if(tracucedRk>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); + if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[tracucedRk]; +} + +void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + if(-meshDimRelToMax>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !"); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) + { + if(((const MEDFileUMeshSplitL1*) (*it))!=0) + { + int ref=(*it)->getMeshDimension(); + if(ref+i!=meshDim+meshDimRelToMax) + throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !"); + } + } +} + +void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) +{ + coords->checkAllocated(); + int nbOfTuples=coords->getNumberOfTuples(); + _coords=coords; + coords->incrRef(); + _fam_coords=DataArrayInt::New(); + _fam_coords->alloc(nbOfTuples,1); + _fam_coords->fillWithZero(); +} + +void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum) throw(INTERP_KERNEL::Exception) +{ + if(grps.empty()) + return ; + std::set grpsName; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + grpsName.insert((*it)->getName()); + if(grpsName.size()!=grps.size()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !"); + if(grpsName.find(std::string(""))!=grpsName.end()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !"); + /* int sz=getSizeAtLevel(meshDimRelToMaxExt); + if(!renum) + { + + }*/ +} + +void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if((DataArrayInt *)_fam_coords) + _fam_coords->fillWithZero(); + return ; + } + MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + l1->eraseFamilyField(); + optimizeFamilies(); +} + +void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception) +{ + std::vector levs=getNonEmptyLevelsExt(); + std::set allFamsIds; + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + const DataArrayInt *ffield=getFamilyFieldAtLevel(*it); + std::set ids=ffield->getDifferentValues(); + std::set res; + std::set_union(ids.begin(),ids.end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin())); + allFamsIds=res; + } +} + +void MEDFileUMesh::setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector& grpNames) throw(INTERP_KERNEL::Exception) +{ + +} + +void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *coords=_coords; + if(!coords) + throw INTERP_KERNEL::Exception("addNodeGroup : no coords set !"); + DataArrayInt *sub=_fam_coords->selectByTupleIdSafe(&ids[0],&ids[0]+ids.size()); + std::set ssub(sub->getConstPointer(),sub->getConstPointer()+sub->getNumberOfTuples()); + +} + +void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception) +{ + std::string oldName=getFamilyNameGivenId(id); + _families.erase(oldName); + _families[newFamName]=id; +} + +void MEDFileUMesh::setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + std::vector levSet=getNonEmptyLevels(); + if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end()) + { + if((DataArrayDouble *)_coords==0) + { + DataArrayDouble *c=m->getCoords(); + if(c) + c->incrRef(); + _coords=c; + } + else + { + if(m->getCoords()!=_coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtRank : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(m->getMeshDimension(),sz); + _ms[sz]=new MEDFileUMeshSplitL1(m); + } + } +} + +void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax); + DataArrayDouble *coo=checkMultiMesh(ms); + if((DataArrayDouble *)_coords==0) + { + coo->incrRef(); + _coords=coo; + } + else + if((DataArrayDouble *)_coords!=coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !"); + _ms[-meshDimRelToMax]->setGroupsFromScratch(ms,_families,_groups); +} + +void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +{ + if(ms.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !"); + +} + +DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx new file mode 100644 index 000000000..d5378c57f --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -0,0 +1,124 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESH_HXX__ +#define __MEDFILEMESH_HXX__ + +#include "MEDFileMeshLL.hxx" + +#include + +namespace ParaMEDMEM +{ + class MEDFileMesh : public RefCountObject + { + public: + static MEDFileMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + void setName(const char *name) { _name=name; } + const char *getName() const { return _name.c_str(); } + void setUnivName(const char *name) { _univ_name=name; } + const char *getUnivName() const { return _univ_name.c_str(); } + void setDescription(const char *name) { _desc_name=name; } + const char *getDescription() const { return _desc_name.c_str(); } + protected: + std::string _name; + std::string _univ_name; + std::string _desc_name; + }; + + class MEDFileUMesh : public MEDFileMesh + { + public: + static MEDFileUMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(); + ~MEDFileUMesh(); + // + void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); + void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); + void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + // + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + int getNumberOfLevels() const { return _ms.size(); } + int getNumberOfNonEmptyLevels() const; + int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); + std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception); + int getMeshDimension() const; + int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getGroupsNames() const; + std::vector getFamiliesNames() const; + std::vector getNonEmptyLevels() const; + std::vector getNonEmptyLevelsExt() const; + DataArrayDouble *getCoords() const; + MEDCouplingUMesh *getGroup(int meshDimRelToMax, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getGroupArr(int meshDimRelToMax, const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getGroups(int meshDimRelToMax, const std::vector& grps, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getGroupsArr(int meshDimRelToMax, const std::vector& grps, bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamily(int meshDimRelToMax, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getFamilyArr(int meshDimRelToMax, const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamilies(int meshDimRelToMax, const std::vector& fams, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getFamiliesArr(int meshDimRelToMax, const std::vector& fams, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeGroupArr(const char *grp, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeGroupsArr(const std::vector& grps, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=true) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getMeshAtRank(int meshDimRelToMax, bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRank0Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM1Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM2Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM3Mesh(bool renum=true) const throw(INTERP_KERNEL::Exception); + // + void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception); + void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum=true) throw(INTERP_KERNEL::Exception); + void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception); + void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector& grpNames) throw(INTERP_KERNEL::Exception); + void addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception); + void setMeshAtRank(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void optimizeFamilies() throw(INTERP_KERNEL::Exception); + private: + MEDFileUMesh(); + MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMax) throw(INTERP_KERNEL::Exception); + void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception); + private: + std::map > _groups; + std::map _families; + std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; + MEDCouplingAutoRefCountObjectPtr _coords; + MEDCouplingAutoRefCountObjectPtr _fam_coords; + MEDCouplingAutoRefCountObjectPtr _num_coords; + int _too_long_str; + }; + + + class MEDFileCMesh : public MEDFileMesh + { + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx new file mode 100644 index 000000000..9fa3dfbe0 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -0,0 +1,253 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMeshElt.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" +#include "CellModel.hxx" + +extern med_geometrie_element typmai3[32]; + +using namespace ParaMEDMEM; + +MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) +{ + med_entite_maillage whichEntity; + if(!isExisting(fid,mName,geoElt,whichEntity)) + return 0; + return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity); +} + +bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity) +{ + static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE}; + int nbOfElt=0; + for(int i=0;i<3;i++) + { + int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD); + if(tmp>nbOfElt) + { + nbOfElt=tmp; + whichEntity=entities[i]; + } + } + return nbOfElt>0; +} + +int MEDFileUMeshPerType::getDim() const +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + return cm.getDimension(); +} + +MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity):_type(type),_entity(entity) +{ + int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD); + if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED) + { + loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity); + return; + } + if(type==INTERP_KERNEL::NORM_POLYGON) + { + loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,entity); + return; + } + //if(type==INTERP_KERNEL::NORM_POLYHED) + loadPolyh(fid,mName,mdim,curNbOfElem,geoElt,entity); +} + +void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity) +{ + _conn=DataArrayInt::New(); + int nbOfNodesPerCell=(geoElt%100); + _conn->alloc((nbOfNodesPerCell+1)*curNbOfElem,1); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + int *connTab=new int[(nbOfNodesPerCell)*curNbOfElem]; + _num=DataArrayInt::New(); + _num->alloc(curNbOfElem,1); + char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1]; + med_booleen inoele, inuele; + _fam=DataArrayInt::New(); + _fam->alloc(curNbOfElem,1); + MEDelementsLire(fid,(char *)mName,mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,_num->getPointer(),&inuele,_fam->getPointer(),curNbOfElem,entity,geoElt,MED_NOD); + delete [] noms; + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + *w2++=0; + const int *wi=connTab; + for(int i=0;i(),-1)); + *w2=w2[-1]+nbOfNodesPerCell+1; + } + delete [] connTab; + if(!inuele) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage entity) +{ + med_int arraySize; + MEDpolygoneInfo(fid,(char *)mName,entity,MED_NOD,&arraySize); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + _conn=DataArrayInt::New(); + _conn->alloc(arraySize+curNbOfElem,1); + _num=DataArrayInt::New(); + _num->alloc(curNbOfElem,1); + _fam=DataArrayInt::New(); + _fam->alloc(curNbOfElem,1); + int *locConn=new int[arraySize]; + MEDpolygoneConnLire(fid,(char *)mName,_conn_index->getPointer(),curNbOfElem+1,locConn,entity,MED_NOD); + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + const int *wi=locConn; + for(int i=0;i(),-1)); + *w2=*w2-1+i; + } + *w2=*w2-1+curNbOfElem; + delete [] locConn; + MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,entity,MED_POLYGONE); + if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,entity,MED_POLYGONE)!=0) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage entity) +{ + med_int indexFaceLgth,connFaceLgth; + MEDpolyedreInfo(fid,(char*)mName,MED_NOD,&indexFaceLgth,&connFaceLgth); + int *index=new int[curNbOfElem+1]; + int *indexFace=new int[indexFaceLgth]; + int *locConn=new int[connFaceLgth]; + _fam=DataArrayInt::New(); + _fam->alloc(curNbOfElem,1); + MEDpolyedreConnLire(fid,(char *)mName,index,curNbOfElem+1,indexFace,indexFaceLgth,locConn,MED_NOD); + MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE); + int arraySize=connFaceLgth; + for(int i=0;ialloc(arraySize+curNbOfElem,1); + int *wFinalConn=_conn->getPointer(); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + int *finalIndex=_conn_index->getPointer(); + finalIndex[0]=0; + for(int i=0;i(),-1)); + for(int j=index[i];j(),-1)); + } + } + delete [] index; + delete [] locConn; + delete [] indexFace; + _num=DataArrayInt::New(); + _num->alloc(curNbOfElem,1); + if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE)!=0) + _num=0; +} + +void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num) +{ + int nbOfCells=m->getNumberOfCells(); + if(nbOfCells<1) + return ; + INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(ikt); + med_geometrie_element curMedType=typmai3[(int)ikt]; + const int *conn=m->getNodalConnectivity()->getConstPointer(); + const int *connI=m->getNodalConnectivityIndex()->getConstPointer(); + if(ikt!=INTERP_KERNEL::NORM_POLYGON && ikt!=INTERP_KERNEL::NORM_POLYHED) + { + int nbNodesPerCell=cm.getNumberOfNodes(); + INTERP_KERNEL::AutoPtr tab=new int[nbNodesPerCell*nbOfCells]; + int *w=tab; + for(int i=0;i(),1)); + MEDconnEcr(fid,(char *)mname,mdim,tab,MED_FULL_INTERLACE,nbOfCells,MED_MAILLE,curMedType,MED_NOD); + } + else + { + if(ikt==INTERP_KERNEL::NORM_POLYGON) + { + INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; + INTERP_KERNEL::AutoPtr tab2=new int[m->getMeshLength()]; + int *wI=tab1; *wI=1; + int *w=tab2; + for(int i=0;i(),1)); + } + MEDpolygoneConnEcr(fid,(char *)mname,tab1,nbOfCells,tab2,MED_MAILLE,MED_NOD); + } + else + { + int meshLgth=m->getMeshLength(); + int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells; + INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; + int *w1=tab1; *w1=1; + INTERP_KERNEL::AutoPtr tab2=new int[nbOfFaces+1]; + int *w2=tab2; *w2=1; + INTERP_KERNEL::AutoPtr bigtab=new int[meshLgth-nbOfCells]; + int *bt=bigtab; + for(int i=0;i(),1)); + int nbOfNode=std::distance(w,wend); + w2[1]=w2[0]+nbOfNode; + if(wend!=conn+connI[i+1]) + w=wend+1; + else + w=wend; + nbOfFaces++; + } + w1[1]=w1[0]+nbOfFaces; + } + MEDpolyedreConnEcr(fid,(char *)mname,tab1,nbOfCells+1,tab2,nbOfFaces+1, + bigtab,MED_NOD); + } + } + if(fam) + MEDfamEcr(fid,(char *)mname,(int *)fam->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); + if(num) + MEDnumEcr(fid,(char *)mname,(int *)num->getConstPointer(),nbOfCells,MED_MAILLE,curMedType); +} diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx new file mode 100644 index 000000000..732ca2b43 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -0,0 +1,67 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESHELT_HXX__ +#define __MEDFILEMESHELT_HXX__ + +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +#include "NormalizedUnstructuredMesh.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + class MEDFileUMeshPerType : public RefCountObject + { + public: + static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2); + static bool isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity); + int getDim() const; + const DataArrayInt *getNodal() const { return _conn; } + const DataArrayInt *getNodalIndex() const { return _conn_index; } + const DataArrayInt *getFam() const { return _fam; } + const DataArrayInt *getNum() const { return _num; } + static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num); + private: + MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity); + void loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity); + void loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage entity); + void loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, + med_entite_maillage entity); + private: + MEDCouplingAutoRefCountObjectPtr _conn; + MEDCouplingAutoRefCountObjectPtr _conn_index; + MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _fam; + INTERP_KERNEL::NormalizedCellType _type; + med_entite_maillage _entity; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx new file mode 100644 index 000000000..15992005f --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -0,0 +1,431 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMeshLL.hxx" +#include "MEDLoaderBase.hxx" + +#include "MEDCouplingUMesh.hxx" + +#include "InterpKernelAutoPtr.hxx" + +#include + +extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2]; +extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2]; +extern med_geometrie_element typmainoeud[1]; + +using namespace ParaMEDMEM; + +MEDFileMeshL2::MEDFileMeshL2():_name(MED_TAILLE_NOM),_description(MED_TAILLE_DESC) +{ +} + +MEDFileUMeshL2::MEDFileUMeshL2() +{ +} + +void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName) +{ + _name.set(mName); + med_maillage type_maillage; + med_int Mdim; + if(MEDmaaInfo(fid,mId,(char *)mName,&Mdim,&type_maillage,_description.getPointer())!=0) + throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !"); + if(type_maillage!=MED_NON_STRUCTURE) + throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !"); + loadConnectivity(fid,Mdim,mName); + loadCoords(fid,mId,Mdim,mName); +} + +void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName) +{ + _per_type_mesh.resize(1); + _per_type_mesh[0].clear(); + for(int j=0;jalloc(nCoords,spaceDim); + double *coordsPtr=_coords->getPointer(); + med_repere repere; + char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + MEDcoordLire(fid,(char *)mName,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); + _fam_coords=DataArrayInt::New(); + _fam_coords->alloc(nCoords,1); + _num_coords=DataArrayInt::New(); + _num_coords->alloc(nCoords,1); + MEDfamLire(fid,(char *)mName,_fam_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE); + if(MEDnumLire(fid,(char *)mName,_num_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE)!=0) + _num_coords=0; + for(int i=0;isetInfoOnComponent(i,info.c_str()); + } + delete [] comp; + delete [] unit; +} + +void MEDFileUMeshL2::sortTypes() +{ + std::set mdims; + std::vector< MEDCouplingAutoRefCountObjectPtr > tmp(_per_type_mesh[0]); + _per_type_mesh.clear(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + mdims.insert((*it)->getDim()); + if(mdims.empty()) + return; + int mdim=*mdims.rbegin(); + _per_type_mesh.resize(mdim+1); + for(int dim=mdim+1;dim!=0;dim--) + { + std::vector< MEDCouplingAutoRefCountObjectPtr >& elt=_per_type_mesh[mdim+1-dim]; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=tmp.begin();it!=tmp.end();it++) + if((*it)->getDim()==dim-1) + elt.push_back(*it); + } +} + +int MEDFileUMeshL2::getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception) +{ + med_maillage type_maillage; + char maillage_description[MED_TAILLE_DESC+1]; + med_int dim; + char nommaa[MED_TAILLE_NOM+1]; + med_int n=MEDnMaa(fid); + bool found=false; + int ret=-1; + std::vector ms; + for(int i=0;i(oss,", ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return ret; +} + +void MEDFileUMeshL2::readFamiliesAndGrps(med_idt fid, const char *meshName, std::map& fams, std::map >& grps) +{ + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + int nfam=MEDnFam(fid,(char *)meshName); + for(int i=0;i& fams, const std::map >& grps) +{ + for(std::map::const_iterator it=fams.begin();it!=fams.end();it++) + { + std::vector grpsOfFam; + for(std::map >::const_iterator it1=grps.begin();it1!=grps.end();it1++) + { + if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end()) + grpsOfFam.push_back((*it1).first); + } + int ngro=grpsOfFam.size(); + INTERP_KERNEL::AutoPtr groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro); + int i=0; + for(std::vector::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++) + MEDLoaderBase::safeStrCpy((*it2).c_str(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,0);//tony too long + INTERP_KERNEL::AutoPtr famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_TAILLE_NOM,famName,0);//tony too long + MEDfamCr(fid,(char *)mname,famName,(*it).second,0,0,0,0,groName,ngro); + } +} + +void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords) +{ + if(!coords) + return ; + int spaceDim=coords->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + for(int i=0;igetInfoOnComponent(i); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } + MEDcoordEcr(fid,(char *)mname,spaceDim,coords->getPointer(),MED_FULL_INTERLACE,coords->getNumberOfTuples(),MED_CART,comp,unit); + MEDfamEcr(fid,(char *)mname,famCoords->getPointer(),famCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE); + if(numCoords) + MEDnumEcr(fid,(char *)mname,numCoords->getPointer(),numCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE); +} + +bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + if((*it)->getFam()==0) + return false; + return true; +} + +bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + if((*it)->getNum()==0) + return false; + return true; +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id) +{ + const std::vector< MEDCouplingAutoRefCountObjectPtr >& v=l2.getLev(id); + if(v.empty()) + return; + int sz=v.size(); + std::vector ms(sz); + for(int i=0;igetDim()); + MEDCouplingAutoRefCountObjectPtr tmp2=l2.getCoords(); + tmp->setCoords(tmp2); + tmp->setConnectivity(const_cast(v[i]->getNodal()),const_cast(v[i]->getNodalIndex())); + ms[i]=tmp; + } + _m_by_types=MEDCouplingUMesh::mergeUMeshesOnSameCoords(ms); + _m_by_types->setName(mName); + if(l2.isFamDefinedOnLev(id)) + { + int nbOfCells=_m_by_types->getNumberOfCells(); + _fam=DataArrayInt::New(); + _fam->alloc(nbOfCells,1); + int *w=_fam->getPointer(); + for(int i=0;igetFam()->getConstPointer(),v[i]->getFam()->getConstPointer()+v[i]->getFam()->getNumberOfTuples(),w); + } + if(l2.isNumDefinedOnLev(id)) + { + int nbOfCells=_m_by_types->getNumberOfCells(); + _num=DataArrayInt::New(); + _num->alloc(nbOfCells,1); + int *w=_num->getPointer(); + for(int i=0;igetNum()->getConstPointer(),v[i]->getNum()->getConstPointer()+v[i]->getNum()->getNumberOfTuples(),w); + _m=(MEDCouplingUMesh *)_m_by_types->deepCpy(); + _m->renumberCells(_num->getConstPointer(),true); + } + else + _m=_m_by_types; + for(int i=0;idecrRef(); +} + +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m) +{ + m->incrRef(); + _m=m; + _m_by_types=(MEDCouplingUMesh *)_m->deepCpy(); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); + _fam=DataArrayInt::New(); + _fam->alloc(m->getNumberOfCells(),1); + _fam->fillWithValue(0); + _m_by_types->renumberCells(da->getConstPointer(),false); +} + +bool MEDFileUMeshSplitL1::empty() const +{ + return ((const MEDCouplingUMesh *)_m_by_types)==0; +} + +int MEDFileUMeshSplitL1::getMeshDimension() const +{ + return _m_by_types->getMeshDimension(); +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector& ids, bool renum) const +{ + MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(ids); + MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); + if(renum) + return renumIfNeeded(m,eltsToKeep->getConstPointer()); + return m; +} + +DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const std::vector& ids, bool renum) const +{ + DataArrayInt *da=_fam->getIdsEqualList(ids); + if(renum) + return renumIfNeededArr(da); + return da; +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const +{ + MEDCouplingAutoRefCountObjectPtr tmp; + if(renum) + tmp=_m; + else + tmp=_m_by_types; + tmp->incrRef(); + return tmp; +} + +const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const +{ + return _fam; +} + +void MEDFileUMeshSplitL1::eraseFamilyField() +{ + _fam->fillWithZero(); +} + +/*! + * This method ignores _m and _m_by_types. + */ +void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception) +{ + int sz=ms.size(); + std::vector< DataArrayInt * > corr; + _m=MEDCouplingUMesh::fuseUMeshesOnSameCoords(ms,0,corr); + std::vector< std::vector > fidsOfGroups; + _fam=DataArrayInt::makePartition(corr,_m->getNumberOfCells(),fidsOfGroups); + int nbOfCells=_m->getNumberOfCells(); + std::map newfams; + std::map famIdTrad; + traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams); + for(int i=0;idecrRef(); + int *w=_fam->getPointer(); + for(int i=0;i ms=_m_by_types->splitByType(); + int start=0; + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) + { + int nbCells=(*it)->getNumberOfCells(); + int end=start+nbCells; + DataArrayInt *fam=0,*num=0; + if((const DataArrayInt *)_fam) + fam=_fam->substr(start,end); + if((const DataArrayInt *)_num) + num=_num->substr(start,end); + MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num); + if(fam) + fam->decrRef(); + if(num) + num->decrRef(); + (*it)->decrRef(); + start=end; + } +} + +MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const +{ + if((const DataArrayInt *)_num==0) + return m; + if(cellIds==0) + m->renumberCells(_num->getConstPointer(),true); + else + { + MEDCouplingAutoRefCountObjectPtr locnum=_num->selectByTupleId(cellIds,cellIds+m->getNumberOfCells()); + m->renumberCells(locnum->getConstPointer(),true); + } + return m; +} + +DataArrayInt *MEDFileUMeshSplitL1::renumber(const DataArrayInt *renum, DataArrayInt *da) +{ + if((const DataArrayInt *)renum==0) + return da; + MEDCouplingAutoRefCountObjectPtr locnum=renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples()); + da->decrRef(); + locnum->incrRef(); + return locnum; +} + +DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const +{ + return renumber(_num,da); +} + +std::vector MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map& families) +{ + int id=-1; + for(std::map::const_iterator it=families.begin();it!=families.end();it++) + id=std::max(id,(*it).second); + if(id==-1) + id=0; + std::vector ret(nb); + for(int i=1;i<=nb;i++) + ret[i]=id+i; + return ret; +} + +void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams) +{ + std::set allfids; + +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx new file mode 100644 index 000000000..57ecb634a --- /dev/null +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -0,0 +1,112 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESHLL_HXX__ +#define __MEDFILEMESHLL_HXX__ + +#include "MEDFileBasis.hxx" +#include "MEDFileMeshElt.hxx" + +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +extern "C" +{ +#include "med.h" +} + +#include + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + class MEDFileMeshL2 : public RefCountObject + { + public: + MEDFileMeshL2(); + const char *getName() const { return _name.getReprForWrite(); } + const char *getDescription() const { return _description.getReprForWrite(); } + protected: + MEDFileString _name; + MEDFileString _description; + }; + + class MEDFileUMeshL2 : public MEDFileMeshL2 + { + public: + MEDFileUMeshL2(); + void loadAll(med_idt fid, int mId, const char *mName); + void loadConnectivity(med_idt fid, int mdim, const char *mName); + void loadCoords(med_idt fid, int mId, int mdim, const char *mName) throw(INTERP_KERNEL::Exception); + int getNumberOfLevels() const { return _per_type_mesh.size(); } + bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); } + const std::vector< MEDCouplingAutoRefCountObjectPtr >& getLev(int levId) const { return _per_type_mesh[levId]; } + bool isFamDefinedOnLev(int levId) const; + bool isNumDefinedOnLev(int levId) const; + MEDCouplingAutoRefCountObjectPtr getCoords() const { return _coords; } + MEDCouplingAutoRefCountObjectPtr getCoordsFamily() const { return _fam_coords; } + MEDCouplingAutoRefCountObjectPtr getCoordsNum() const { return _num_coords; } + static int getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception); + static void readFamiliesAndGrps(med_idt fid, const char *mname, std::map& fams, std::map >& grps); + static void writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map& fams, const std::map >& grps); + static void writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords); + private: + void sortTypes(); + private: + std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > _per_type_mesh; + MEDCouplingAutoRefCountObjectPtr _coords; + MEDCouplingAutoRefCountObjectPtr _fam_coords; + MEDCouplingAutoRefCountObjectPtr _num_coords; + }; + + class MEDFileUMeshL2CMesh : public MEDFileMeshL2 + { + }; + + class MEDFileUMeshSplitL1 : public RefCountObject + { + public: + MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); + MEDFileUMeshSplitL1(MEDCouplingUMesh *m); + bool empty() const; + int getMeshDimension() const; + MEDCouplingUMesh *getFamilyPart(const std::vector& ids, bool renum) const; + DataArrayInt *getFamilyPartArr(const std::vector& ids, bool renum) const; + MEDCouplingUMesh *getWholeMesh(bool renum) const; + const DataArrayInt *getFamilyField() const; + void eraseFamilyField(); + void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, + std::map >& groups) throw(INTERP_KERNEL::Exception); + void write(med_idt fid, const char *mName, int mdim) const; + static std::vector getNewFamiliesNumber(int nb, const std::map& families); + static void traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, + std::map& famIdTrad, std::map& newfams); + static DataArrayInt *renumber(const DataArrayInt *renum, DataArrayInt *da); + private: + MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const; + DataArrayInt *renumIfNeededArr(DataArrayInt *da) const; + private: + MEDCouplingAutoRefCountObjectPtr _m_by_types; + MEDCouplingAutoRefCountObjectPtr _fam; + MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _m; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx new file mode 100644 index 000000000..222d8a860 --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -0,0 +1,90 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include + +med_mode_acces MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception) +{ + switch(medloaderwritemode) + { + case 2: + return MED_CREATION; + case 1: + return MED_LECTURE_AJOUT; + case 0: + return MED_LECTURE_ECRITURE; + default: + throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)"); + } +} + +void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception) +{ + if(code==-1) + { + std::ostringstream oss; + oss << "MEDFile has returned an error code (" << code <<") : " << msg; + MEDfermer(fid); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + int status=MEDLoaderBase::getStatusOfFile(fileName); + std::ostringstream oss; + oss << " File : \"" << fileName << "\""; + switch(status) + { + case MEDLoaderBase::DIR_LOCKED: + { + oss << " has been detected as unreadable : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::NOT_EXIST: + { + oss << " has been detected as NOT EXISTING : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::EXIST_WRONLY: + { + oss << " has been detected as WRITE ONLY : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + int fid=MEDouvrir((char *)fileName,MED_LECTURE); + if(fid<0) + { + oss << " has been detected as unreadable by MED file : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + oss << " has been detected readable but "; + int major,minor,release; + MEDversionLire(fid,&major,&minor,&release); + if(major<2 || (major==2 && minor<2)) + { + oss << "version of MED file is < 2.2 : impossible to read anything !"; + MEDfermer(fid); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDfermer(fid); +} diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx new file mode 100644 index 000000000..05f3f4e1c --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEUTILITIES_HXX__ +#define __MEDFILEUTILITIES_HXX__ + +#include "InterpKernelException.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace MEDFileUtilities +{ + med_mode_acces TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception); + void CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception); + void CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception); +} + +#endif diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index cde077cee..15f179b3b 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -19,12 +19,15 @@ #include "MEDLoader.hxx" #include "MEDLoaderBase.hxx" +#include "MEDFileUtilities.hxx" #include "CellModel.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingGaussLocalization.hxx" +#include "InterpKernelAutoPtr.hxx" + extern "C" { #include "med.h" @@ -37,6 +40,7 @@ extern "C" #include #include #include +#include med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1, MED_SEG2, @@ -300,43 +304,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) @@ -434,6 +402,72 @@ std::vector MEDLoader::GetMeshFamiliesNames(const char *fileName, c MEDfermer(fid); return ret; } + +std::vector MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception) +{ + CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + std::vector ret; + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + for(int i=0;i attide=new int[natt]; + INTERP_KERNEL::AutoPtr attval=new int[natt]; + INTERP_KERNEL::AutoPtr attdes=new char[MED_TAILLE_DESC*natt+1]; + INTERP_KERNEL::AutoPtr gro=new char[MED_TAILLE_LNOM*ngro+1]; + MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); + for(int j=0;j MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception) +{ + CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + std::vector ret; + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + bool found=false; + for(int i=0;i attide=new int[natt]; + INTERP_KERNEL::AutoPtr attval=new int[natt]; + INTERP_KERNEL::AutoPtr attdes=new char[MED_TAILLE_DESC*natt+1]; + INTERP_KERNEL::AutoPtr gro=new char[MED_TAILLE_LNOM*ngro+1]; + MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); + found=(cur==famName); + if(found) + for(int j=0;j MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { @@ -812,7 +846,7 @@ double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const ch // bool found=false; bool found2=false; - double ret; + double ret=std::numeric_limits::max(); for(int i=0;i& ids, const std::vector& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception) { + if(meshDimRelToMax>0) + throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !"); //Extraction data from MED file. med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); std::string trueMeshName; @@ -1791,7 +1827,7 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char { std::vector ci(cellIds.size()); std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); - ParaMEDMEM::MEDCouplingUMesh *mesh2; + ParaMEDMEM::MEDCouplingUMesh *mesh2=0; if(typeOfOutField==ON_CELLS) { if(newMesh) diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index b90cad0f7..caf103fc5 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -90,6 +90,8 @@ class MEDLOADER_EXPORT MEDLoader static std::vector GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index 3a2fbb760..484e22f69 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -36,10 +36,13 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ +MEDFileMeshElt.hxx MEDFileBasis.hxx dist_libmedloader_la_SOURCES= \ -MEDLoader.cxx MEDLoaderBase.cxx +MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ +MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ +MEDFileMeshLL.cxx libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/MEDLoader.i similarity index 82% rename from src/MEDLoader/Swig/libMEDLoader_Swig.i rename to src/MEDLoader/Swig/MEDLoader.i index 5feded4d5..e6f960b7a 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -17,22 +17,30 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -%module libMEDLoader_Swig +%module MEDLoader #define MEDCOUPLING_EXPORT #define MEDLOADER_EXPORT -%include "libMEDCoupling_Swig.i" +%include "MEDCoupling.i" %{ #include "MEDLoader.hxx" +#include "MEDFileMesh.hxx" #include "MEDLoaderTypemaps.i" + +using namespace ParaMEDMEM; %} #if SWIG_VERSION >= 0x010329 %template() std::vector; #endif +%typemap(out) ParaMEDMEM::MEDFileMesh* +{ + $result=convertMEDFileMesh($1,$owner); +} + %newobject MEDLoader::ReadUMeshFromFamilies; %newobject MEDLoader::ReadUMeshFromGroups; %newobject MEDLoader::ReadUMeshFromFile; @@ -41,6 +49,25 @@ %newobject MEDLoader::ReadFieldNode; %newobject MEDLoader::ReadFieldGauss; %newobject MEDLoader::ReadFieldGaussNE; +%newobject ParaMEDMEM::MEDFileUMesh::New; +%newobject ParaMEDMEM::MEDFileUMesh::getCoords; +%newobject ParaMEDMEM::MEDFileUMesh::getGroup; +%newobject ParaMEDMEM::MEDFileUMesh::getGroups; +%newobject ParaMEDMEM::MEDFileUMesh::getFamily; +%newobject ParaMEDMEM::MEDFileUMesh::getFamilies; +%newobject ParaMEDMEM::MEDFileUMesh::getGroupArr; +%newobject ParaMEDMEM::MEDFileUMesh::getGroupsArr; +%newobject ParaMEDMEM::MEDFileUMesh::getFamilyArr; +%newobject ParaMEDMEM::MEDFileUMesh::getFamiliesArr; +%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupArr; +%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupsArr; +%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamilyArr; +%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamiliesArr; +%newobject ParaMEDMEM::MEDFileUMesh::getMeshAtRank; +%newobject ParaMEDMEM::MEDFileUMesh::getRank0Mesh; +%newobject ParaMEDMEM::MEDFileUMesh::getRankM1Mesh; +%newobject ParaMEDMEM::MEDFileUMesh::getRankM2Mesh; +%newobject ParaMEDMEM::MEDFileUMesh::getRankM3Mesh; class MEDLoader { @@ -53,6 +80,8 @@ public: static std::vector GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception); static std::vector GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); @@ -152,9 +181,19 @@ public: PyList_SetItem(ret,i,PyInt_FromLong((int)v[i])); return ret; } + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector grps; + converPyListToVecString(li,grps); + return MEDLoader::ReadUMeshFromGroups(fileName,meshName,meshDimRelToMax,grps); + } + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector fams; + converPyListToVecString(li,fams); + return MEDLoader::ReadUMeshFromFamilies(fileName,meshName,meshDimRelToMax,fams); + } } - static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); - static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingFieldDouble *ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); @@ -168,3 +207,6 @@ public: static void WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception); static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception); }; + +%include "MEDFileMesh.hxx" + diff --git a/src/MEDLoader/Swig/MEDLoaderDataForTest.py b/src/MEDLoader/Swig/MEDLoaderDataForTest.py index 2ec4ac837..a0f370d8d 100644 --- a/src/MEDLoader/Swig/MEDLoaderDataForTest.py +++ b/src/MEDLoader/Swig/MEDLoaderDataForTest.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDLoader_Swig import * +from MEDLoader import * from math import pi,e,sqrt class MEDLoaderDataForTest: @@ -195,7 +195,7 @@ class MEDLoaderDataForTest: vec=[0.,1.,0.] pt=[0.,0.,0.] m1d.rotate(pt,vec,-pi/2.); - ret=m3dsurf.buildExtrudedMeshFromThis(m1d,0); + ret=m3dsurf.buildExtrudedMesh(m1d,0); return ret; def buildVecFieldOnCells_1(cls): diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index e0c9a080a..8b9e8348a 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDLoader_Swig import * +import MEDLoader import unittest from math import pi,e,sqrt from MEDLoaderDataForTest import MEDLoaderDataForTest @@ -27,52 +27,52 @@ class MEDLoaderTest(unittest.TestCase): def testMesh1DRW(self): mesh=MEDLoaderDataForTest.build1DMesh_1(); mesh.checkCoherency(); - MEDLoader.WriteUMesh("Pyfile1.med",mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile1.med",mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh("Pyfile1.med",mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile1.med",mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass def testMesh2DCurveRW(self): mesh=MEDLoaderDataForTest.build2DCurveMesh_1(); mesh.checkCoherency(); - MEDLoader.WriteUMesh("Pyfile2.med",mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile2.med",mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh("Pyfile2.med",mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile2.med",mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass def testMesh2DRW(self): mesh=MEDLoaderDataForTest.build2DMesh_1(); mesh.checkCoherency(); - MEDLoader.WriteUMesh("Pyfile3.med",mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile3.med",mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh("Pyfile3.med",mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile3.med",mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass def testMesh3DSurfRW(self): mesh=MEDLoaderDataForTest.build3DSurfMesh_1(); mesh.checkCoherency(); - MEDLoader.WriteUMesh("Pyfile4.med",mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile4.med",mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh("Pyfile4.med",mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile4.med",mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass def testMesh3DRW(self): mesh=MEDLoaderDataForTest.build3DMesh_1(); mesh.checkCoherency(); - MEDLoader.WriteUMesh("Pyfile5.med",mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile5.med",mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh("Pyfile5.med",mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile5.med",mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass def testFieldRW1(self): f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); - MEDLoader.WriteField("Pyfile6.med",f1,True); - f2=MEDLoader.ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1); + MEDLoader.MEDLoader.WriteField("Pyfile6.med",f1,True); + f2=MEDLoader.MEDLoader.ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); # f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); - MEDLoader.WriteField("Pyfile7.med",f1,True); - f2=MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); + MEDLoader.MEDLoader.WriteField("Pyfile7.med",f1,True); + f2=MEDLoader.MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); pass @@ -81,46 +81,46 @@ class MEDLoaderTest(unittest.TestCase): VAL1=12345.67890314; VAL2=-1111111111111.; f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); - MEDLoader.WriteField(fileName,f1,True); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); f1.setTime(10.,8,9); f1.getArray().setIJ(0,0,VAL1); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(10.14,18,19); f1.getArray().setIJ(0,0,VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); #retrieving time steps... - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),8,9); + f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),8,9); f1.setTime(10.,8,9); f1.getArray().setIJ(0,0,VAL1); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),0,1); + f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),0,1); f3=MEDLoaderDataForTest.buildVecFieldOnCells_1(); self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),18,19); + f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),18,19); f1.setTime(10.14,18,19); f1.getArray().setIJ(0,0,VAL2); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); #test of throw on invalid (dt,it) - self.assertRaises(Exception,MEDLoader.ReadFieldCell,fileName,f1.getMesh().getName(),0,f1.getName(),28,19); + self.assertRaises(Exception,MEDLoader.MEDLoader.ReadFieldCell,fileName,f1.getMesh().getName(),0,f1.getName(),28,19); #ON NODES f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); fileName2="Pyfile9.med"; - MEDLoader.WriteField(fileName2,f1,True); + MEDLoader.MEDLoader.WriteField(fileName2,f1,True); f1.setTime(110.,108,109); tmp=f1.getArray().getPointer(); f1.getArray().setIJ(0,3,VAL1); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1); f1.setTime(210.,208,209); f1.getArray().setIJ(0,3,VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1); - f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),108,109); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1); + f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),108,109); f1.setTime(110.,108,109); f1.getArray().setIJ(0,3,VAL1); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); - f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),2,3); + f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),2,3); f3=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); - f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),208,209); + f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),208,209); f1.setTime(210.,208,209); f1.getArray().setIJ(0,3,VAL2); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); @@ -142,72 +142,72 @@ class MEDLoaderTest(unittest.TestCase): f1.setTime(10.,8,9); tmp=f1.getArray().getPointer(); f1.getArray().setIJ(0,0,VAL1); - MEDLoader.WriteField(fileName,f1,True); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); f1.setTime(10.14,18,19); f1.getArray().setIJ(0,0,VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.getMesh().setName(name2); f1.setTime(10.55,28,29); f1.getArray().setIJ(0,0,3*VAL1); - MEDLoader.WriteField(fileName,f1,False); - vec=MEDLoader.GetMeshNamesOnField(fileName,name1); + MEDLoader.MEDLoader.WriteField(fileName,f1,False); + vec=MEDLoader.MEDLoader.GetMeshNamesOnField(fileName,name1); self.assertEqual(2,len(vec)); self.assertTrue(vec[0]==name3); self.assertTrue(vec[1]==name2); f1.setTime(10.66,38,39); f1.getArray().setIJ(0,0,3*VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(10.77,48,49); f1.getArray().setIJ(0,0,4*VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); #ON NODES f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); f1.setName(name1); f1.getMesh().setName(name2); f1.setTime(110.,8,9); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(110.,108,109); tmp=f1.getArray().getPointer(); f1.getArray().setIJ(0,3,VAL1); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setTime(210.,208,209); f1.getArray().setIJ(0,3,VAL2); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); # - it1=MEDLoader.GetCellFieldIterations(fileName,name3,name1); + it1=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name3,name1); self.assertEqual(2,len(it1)); self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]); self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]); - it2=MEDLoader.GetCellFieldIterations(fileName,name2,name1); + it2=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name2,name1); self.assertEqual(3,len(it2)); self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]); self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]); self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]); - it3=MEDLoader.GetNodeFieldIterations(fileName,name2,name1); + it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name2,name1); self.assertEqual(3,len(it3)); self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]); self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]); self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]); - it4=MEDLoader.GetNodeFieldIterations(fileName,name3,name1); + it4=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1); self.assertTrue(len(it4)==0); # # - f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29); self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39); self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13); - f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49); + f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49); self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13); # - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9); self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109); self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13); - f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209); + f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209); self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13); pass @@ -220,66 +220,78 @@ class MEDLoaderTest(unittest.TestCase): part2=[3,4,13,14] mesh3=mesh1.buildPartOfMySelf(part2,True); mesh3.setName("mesh3"); - mesh4=MEDCouplingUMesh.New(); + mesh4=MEDLoader.MEDCouplingUMesh.New(); mesh4.setName("mesh4"); mesh4.setMeshDimension(3); mesh4.allocateCells(1); conn=[0,11,1,3] - mesh4.insertNextCell(NORM_TETRA4,4,conn[0:4]) + mesh4.insertNextCell(MEDLoader.NORM_TETRA4,4,conn[0:4]) mesh4.finishInsertingCells(); mesh4.setCoords(mesh1.getCoords()); meshes=[mesh1,mesh2,mesh3,mesh4] mnane="3DToto"; - MEDLoader.WriteUMeshesPartition(fileName,mnane,meshes,True); + MEDLoader.MEDLoader.WriteUMeshesPartition(fileName,mnane,meshes,True); # - mesh5=MEDLoader.ReadUMeshFromFile(fileName,mnane); + mesh5=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,mnane); mesh1.setName(mnane); part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] mesh6=mesh5.buildPartOfMySelf(part3,True); mesh6.setName(mnane); self.assertTrue(mesh6.isEqual(mesh1,1e-12)); - grps=MEDLoader.GetMeshGroupsNames(fileName,mnane); + grps=MEDLoader.MEDLoader.GetMeshGroupsNames(fileName,mnane); self.assertEqual(4,len(grps)); grps.index("mesh2"); grps.index("mesh3"); grps.index("mesh4"); grps.index("3DMesh_1"); # - vec=["mesh2"]; - mesh2_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); + vec=("mesh2",); + mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); vec=["mesh3"]; - mesh3_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); + mesh3_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); self.assertTrue(mesh3_2.isEqual(mesh3,1e-12)); vec=["mesh4"]; - mesh4_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); + mesh4_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); self.assertTrue(mesh4_2.isEqual(mesh4,1e-12)); - vec=["3DMesh_1"]; - mesh1_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); + vec="3DMesh_1"; + mesh1_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); mesh1.setName("3DMesh_1"); self.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); # vec=["Family_4","Family_2"]; - mesh2_2=MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec); + mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec); mesh2_2.setName("mesh2"); self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); + # + ret=MEDLoader.MEDLoader.GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"); + self.assertEqual(4,len(ret)); + self.assertEqual(ret[0],"Family_1"); + self.assertEqual(ret[1],"Family_2"); + self.assertEqual(ret[2],"Family_3"); + self.assertEqual(ret[3],"Family_4"); + # + ret1=MEDLoader.MEDLoader.GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2"); + self.assertEqual(2,len(ret1)); + self.assertEqual(ret1[0],"3DMesh_1"); + self.assertEqual(ret1[1],"mesh2"); pass def testFieldProfilRW1(self): fileName="Pyfile12.med"; mesh1=MEDLoaderDataForTest.build3DMesh_1(); da,b,newNbOfNodes=mesh1.mergeNodes(1e-12); - MEDLoader.WriteUMesh(fileName,mesh1,True); + MEDLoader.MEDLoader.WriteUMesh(fileName,mesh1,True); part1=[1,2,4,13,15] mesh2=mesh1.buildPartOfMySelf(part1,True); mesh2.setName(mesh1.getName());#<- important for the test # nbOfCells=mesh2.getNumberOfCells(); self.assertEqual(5,nbOfCells); - f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME); f1.setName("VectorFieldOnCells"); f1.setMesh(mesh2); - array=DataArrayDouble.New(); + array=MEDLoader.DataArrayDouble.New(); array.alloc(nbOfCells,2); f1.setArray(array); arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] @@ -287,9 +299,9 @@ class MEDLoaderTest(unittest.TestCase): f1.setTime(3.14,2,7); f1.checkCoherency(); # - MEDLoader.WriteField(fileName,f1,False);#<- False important for the test + MEDLoader.MEDLoader.WriteField(fileName,f1,False);#<- False important for the test # - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); + f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); f2.checkCoherency(); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); # @@ -298,16 +310,16 @@ class MEDLoaderTest(unittest.TestCase): def testFieldGaussRW1(self): fileName="Pyfile13.med"; f1=MEDLoaderDataForTest.buildVecFieldOnGauss_1(); - MEDLoader.WriteField(fileName,f1,True); - f2=MEDLoader.ReadField(ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); + f2=MEDLoader.MEDLoader.ReadField(MEDLoader.ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); pass def testFieldGaussNERW1(self): fileName="Pyfile14.med"; f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1(); - MEDLoader.WriteField(fileName,f1,True); - f2=MEDLoader.ReadField(ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); + f2=MEDLoader.MEDLoader.ReadField(MEDLoader.ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); pass @@ -317,8 +329,8 @@ class MEDLoaderTest(unittest.TestCase): renumber1=[2,5,1,0,3,4] mesh.renumberCells(renumber1,False); mesh.checkCoherency(); - MEDLoader.WriteUMesh(fileName,mesh,True); - mesh_rw=MEDLoader.ReadUMeshFromFile(fileName,mesh.getName(),0); + MEDLoader.MEDLoader.WriteUMesh(fileName,mesh,True); + mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,mesh.getName(),0); self.assertTrue(mesh.isEqual(mesh_rw,1e-12)); pass @@ -333,23 +345,23 @@ class MEDLoaderTest(unittest.TestCase): m.renumberCells(renum,False); m.orientCorrectlyPolyhedrons(); # Writing - MEDLoader.WriteUMesh(fileName,m,True); + MEDLoader.MEDLoader.WriteUMesh(fileName,m,True); f1Tmp=m.getMeasureField(False); - f1=f1Tmp.buildNewTimeReprFromThis(ONE_TIME,False); + f1=f1Tmp.buildNewTimeReprFromThis(MEDLoader.ONE_TIME,False); f1.setTime(0.,1,2); f_1=f1.cloneWithMesh(True); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.applyFunc("2*x"); f1.setTime(0.01,3,4); f_2=f1.cloneWithMesh(True); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.applyFunc("2*x/3"); f1.setTime(0.02,5,6); f_3=f1.cloneWithMesh(True); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); # Reading its=[(1,2),(3,4),(5,6)]; - fs=MEDLoader.ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its); + fs=MEDLoader.MEDLoader.ReadFieldsOnSameMesh(MEDLoader.ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its); self.assertEqual(3,len(fs)); self.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12)); self.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12)); @@ -367,18 +379,18 @@ class MEDLoaderTest(unittest.TestCase): m2d.renumberCells(renumber,False); m2d.setName("ExampleOfMultiDimW"); meshes=[m2d,m3d] - MEDLoader.WriteUMeshes(fileName,meshes,True); - m3d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),0); + MEDLoader.MEDLoader.WriteUMeshes(fileName,meshes,True); + m3d_bis=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),0); self.assertTrue(not m3d_bis.isEqual(m3d,1e-12)); m3d_bis.setName(m3d.getName()); self.assertTrue(m3d_bis.isEqual(m3d,1e-12)); - m2d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces + m2d_bis=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces self.assertTrue(m2d_bis.isEqual(m2d,1e-12)); # Creation of a field on faces. - f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME); f1.setName("FieldOnFacesShuffle"); f1.setMesh(m2d); - array=DataArrayDouble.New(); + array=MEDLoader.DataArrayDouble.New(); arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] array.setValues(arr1,m2d.getNumberOfCells(),2); array.setInfoOnComponent(0,"plkj (mm)"); @@ -387,8 +399,8 @@ class MEDLoaderTest(unittest.TestCase): tmp=array.setValues(arr1,m2d.getNumberOfCells(),2); f1.setTime(3.14,2,7); f1.checkCoherency(); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7); self.assertTrue(f2.isEqual(f1,1e-12,1e-12)); pass @@ -397,11 +409,11 @@ class MEDLoaderTest(unittest.TestCase): fileName2="Pyfile20.med"; m=MEDLoaderDataForTest.build2DMesh_1(); nbOfNodes=m.getNumberOfNodes(); - MEDLoader.WriteUMesh(fileName,m,True); - f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + MEDLoader.MEDLoader.WriteUMesh(fileName,m,True); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME); f1.setName("VFieldOnNodes"); f1.setMesh(m); - array=DataArrayDouble.New(); + array=MEDLoader.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); @@ -412,17 +424,17 @@ class MEDLoaderTest(unittest.TestCase): 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 + MEDLoader.MEDLoader.WriteField(fileName,f2,False);#<- False important for the test # - f3=MEDLoader.ReadFieldNode(fileName,f2.getMesh().getName(),0,f2.getName(),2,7); + f3=MEDLoader.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); + MEDLoader.MEDLoader.WriteUMesh(fileName2,m,True); + MEDLoader.MEDLoader.WriteField(fileName2,f2,False);#<- False important for the test + f3=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f2.getMesh().getName(),0,f2.getName(),2,7); f3.checkCoherency(); self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); # @@ -431,14 +443,14 @@ class MEDLoaderTest(unittest.TestCase): def testFieldNodeProfilRW2(self): fileName="Pyfile23.med"; mesh=MEDLoaderDataForTest.build3DSurfMesh_1(); - MEDLoader.WriteUMesh(fileName,mesh,True); + MEDLoader.MEDLoader.WriteUMesh(fileName,mesh,True); # - f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.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=MEDLoader.DataArrayDouble.New(); array.setValues(arr2,12,2); f1.setArray(array); array.setInfoOnComponent(0,"plkj (mm)"); @@ -449,8 +461,8 @@ class MEDLoaderTest(unittest.TestCase): 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); + MEDLoader.MEDLoader.WriteField(fileName,f1,False);#<- False important for the test + f2=MEDLoader.MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); self.assertTrue(f2.isEqual(f1,1e-12,1e-12)); # pass @@ -458,10 +470,10 @@ class MEDLoaderTest(unittest.TestCase): def testMixCellAndNodesFieldRW1(self): fileName="Pyfile21.med"; mesh=MEDLoaderDataForTest.build3DSurfMesh_1(); - f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME); f1.setName("FieldMix"); f1.setMesh(mesh); - array=DataArrayDouble.New(); + array=MEDLoader.DataArrayDouble.New(); f1.setArray(array); arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.] array.setValues(arr1,6,2); @@ -470,10 +482,10 @@ class MEDLoaderTest(unittest.TestCase): f1.setTime(3.14,2,7); f1.checkCoherency(); # - f2=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + f2=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME); f2.setName("FieldMix"); f2.setMesh(mesh); - array=DataArrayDouble.New(); + array=MEDLoader.DataArrayDouble.New(); f2.setArray(array); 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.] @@ -483,26 +495,26 @@ class MEDLoaderTest(unittest.TestCase): f2.setTime(3.17,2,7); f2.checkCoherency(); # - MEDLoader.WriteField(fileName,f1,True); - ts=MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName()); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); + ts=MEDLoader.MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName()); self.assertEqual(1,len(ts)); - self.assertEqual(ON_CELLS,ts[0]); - fs=MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName()); + self.assertEqual(MEDLoader.ON_CELLS,ts[0]); + fs=MEDLoader.MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName()); self.assertEqual(1,len(fs)); self.assertTrue(fs[0]=="FieldMix"); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f2); - fs=MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName()); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f2); + fs=MEDLoader.MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName()); self.assertEqual(1,len(fs)); self.assertTrue(fs[0]=="FieldMix"); # - ts=MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName()); + ts=MEDLoader.MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName()); self.assertEqual(2,len(ts)); - self.assertEqual(ON_NODES,ts[0]); - self.assertEqual(ON_CELLS,ts[1]); + self.assertEqual(MEDLoader.ON_NODES,ts[0]); + self.assertEqual(MEDLoader.ON_CELLS,ts[1]); # - f3=MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); + f3=MEDLoader.MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); - f3=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); + f3=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); self.assertTrue(f3.isEqual(f1,1e-12,1e-12)); # pass @@ -510,27 +522,27 @@ class MEDLoaderTest(unittest.TestCase): def testGetAllFieldNamesRW1(self): fileName="Pyfile22.med"; mesh=MEDLoaderDataForTest.build2DMesh_2(); - f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME); f1.setName("Field1"); f1.setTime(3.44,5,6); f1.setMesh(mesh); f1.fillFromAnalytic(2,"x+y"); - MEDLoader.WriteField(fileName,f1,True); + MEDLoader.MEDLoader.WriteField(fileName,f1,True); f1.setTime(1002.3,7,8); f1.fillFromAnalytic(2,"x+77.*y"); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); f1.setName("Field2"); - MEDLoader.WriteField(fileName,f1,False); + MEDLoader.MEDLoader.WriteField(fileName,f1,False); f1.setName("Field3"); mesh.setName("2DMesh_2Bis"); - MEDLoader.WriteField(fileName,f1,False); - f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + MEDLoader.MEDLoader.WriteField(fileName,f1,False); + f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.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); + MEDLoader.MEDLoader.WriteField(fileName,f1,False); + fs=MEDLoader.MEDLoader.GetAllFieldNames(fileName); self.assertEqual(4,len(fs)); self.assertTrue(fs[0]=="Field1"); self.assertTrue(fs[1]=="Field2"); diff --git a/src/MEDLoader/Swig/MEDLoaderTest2.py b/src/MEDLoader/Swig/MEDLoaderTest2.py index bc39c1bc0..bace6ddbc 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest2.py +++ b/src/MEDLoader/Swig/MEDLoaderTest2.py @@ -18,7 +18,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libMEDLoader_Swig import * +from MEDLoader import * import unittest from math import pi,e,sqrt from MEDLoaderDataForTest import MEDLoaderDataForTest diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py new file mode 100644 index 000000000..532292e19 --- /dev/null +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -0,0 +1,92 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from MEDLoader import * +import unittest +from math import pi,e,sqrt +from MEDLoaderDataForTest import MEDLoaderDataForTest + +class MEDLoaderTest(unittest.TestCase): + def testMEDMesh1(self): + fileName="Pyfile18.med" + mname="ExampleOfMultiDimW" + medmesh=MEDFileUMesh.New(fileName,mname) + self.assertEqual((0,-1),medmesh.getNonEmptyLevels()) + m1_0=medmesh.getRank0Mesh() + m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0) + self.assertTrue(m1_0.isEqual(m1_1,1e-12)); + m2_0=medmesh.getRankM1Mesh() + m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1) + self.assertTrue(m2_0.isEqual(m2_1,1e-12)); + pass + def testMEDMesh2(self): + fileName="Pyfile10.med" + mname="3DToto" + outFileName="MEDFileMesh1.med" + medmesh=MEDFileUMesh.New(fileName,mname) + self.assertEqual((0,),medmesh.getNonEmptyLevels()) + m1_0=medmesh.getRank0Mesh() + m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0) + self.assertTrue(m1_0.isEqual(m1_1,1e-12)); + g1_0=medmesh.getGroup(0,"mesh2") + g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh2"]); + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + g1_0=medmesh.getGroup(0,"mesh3") + g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3"]); + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + g1_0=medmesh.getGroups(0,["mesh3","mesh2"]) + g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]); + g1_1.setName(g1_0.getName()) + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + g1_0=medmesh.getFamily(0,"Family_2") + g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2"]); + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + g1_0=medmesh.getFamilies(0,["Family_2","Family_4"]) + g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2","Family_4"]); + g1_1.setName(g1_0.getName()) + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + self.assertTrue(g1_0.isEqual(g1_1,1e-12)); + medmesh.write(outFileName,2); + self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues()); + self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2").getValues()); + self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"]).getValues()); + self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"]).getValues()); + famn=medmesh.getFamilyNameGivenId(0) + self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn).getValues()); + # without renum + self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues()); + self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues()); + self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues()); + self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues()); + self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn,False).getValues()); + pass + def testMEDMesh3(self): + mm=MEDFileUMesh.New() + mm.setName("MyFirstMEDCouplingMEDmesh") + mm.setDescription("IHopeToConvinceLastMEDMEMUsers") + c=DataArrayDouble.New() + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + c.setValues(coords,9,2) + mm.setCoords(c) + mm.addNodeGroup + pass + pass + +unittest.main() diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index 94811c36d..b6f40fa23 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -19,6 +19,21 @@ #include +static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) +{ + PyObject *ret=0; + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner); + if(!ret) + { + PyErr_SetString(PyExc_TypeError,"Not recognized type of MEDFileMesh on downcast !"); + PyErr_Print(); + } + return ret; +} + static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) { std::vector > ret; @@ -87,6 +102,45 @@ static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) return ret; } +static void converPyListToVecString(PyObject *pyLi, std::vector& v) +{ + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + v.resize(size); + for(int i=0;i& li) { int sz=li.size(); diff --git a/src/MEDLoader/Swig/Makefile.am b/src/MEDLoader/Swig/Makefile.am index ab110a19d..dcdff94c2 100644 --- a/src/MEDLoader/Swig/Makefile.am +++ b/src/MEDLoader/Swig/Makefile.am @@ -21,35 +21,36 @@ # include $(top_srcdir)/adm_local/unix/make_common_starter.am -lib_LTLIBRARIES = _libMEDLoader_Swig.la +lib_LTLIBRARIES = _MEDLoader.la salomeinclude_HEADERS = \ - libMEDLoader_Swig.i MEDLoaderTypemaps.i + MEDLoader.i MEDLoaderTypemaps.i -SWIG_DEF = libMEDLoader_Swig.i MEDLoaderTypemaps.i +SWIG_DEF = MEDLoader.i MEDLoaderTypemaps.i SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../../MEDCoupling -I$(srcdir)/../../MEDCoupling_Swig \ -I$(srcdir)/../../INTERP_KERNEL -I$(srcdir)/../../INTERP_KERNEL/Bases -dist__libMEDLoader_Swig_la_SOURCES = $(SWIG_DEF) -nodist__libMEDLoader_Swig_la_SOURCES = libMEDLoader_Swig_wrap.cxx -libMEDLoader_Swig.py: libMEDLoader_Swig_wrap.cxx +dist__MEDLoader_la_SOURCES = $(SWIG_DEF) +nodist__MEDLoader_la_SOURCES = MEDLoader_wrap.cxx +MEDLoader.py: MEDLoader_wrap.cxx -libMEDLoader_Swig_wrap.cxx: $(SWIG_DEF) +MEDLoader_wrap.cxx: $(SWIG_DEF) $(SWIG) $(SWIG_FLAGS) -o $@ $< -_libMEDLoader_Swig_la_CPPFLAGS = $(PYTHON_INCLUDES) \ +_MEDLoader_la_CPPFLAGS = $(PYTHON_INCLUDES) \ $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../../INTERP_KERNEL \ -I$(srcdir)/.. -I$(srcdir)/../../MEDCoupling_Swig -I$(srcdir)/../../INTERP_KERNEL/Bases \ -I$(srcdir)/../../MEDCoupling -_libMEDLoader_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) \ +_MEDLoader_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) \ ../../MEDCoupling/libmedcoupling.la ../../INTERP_KERNEL/libinterpkernel.la \ ../libmedloader.la -CLEANFILES = libMEDLoader_Swig_wrap.cxx libMEDLoader_Swig.py +CLEANFILES = MEDLoader_wrap.cxx MEDLoader.py -dist_salomescript_DATA= libMEDLoader_Swig.py MEDLoaderDataForTest.py MEDLoaderTest.py MEDLoaderTest2.py +dist_salomescript_DATA= MEDLoaderDataForTest.py MEDLoaderTest.py MEDLoaderTest2.py MEDLoaderTest3.py libMEDLoader_Swig.py +nodist_salomescript_DATA = MEDLoader.py UNIT_TEST_PROG = MEDLoaderTest.py MEDLoaderTest2.py \ No newline at end of file diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.py b/src/MEDLoader/Swig/libMEDLoader_Swig.py similarity index 67% rename from src/ParaMEDMEM_Swig/ParaMEDMEM.py rename to src/MEDLoader/Swig/libMEDLoader_Swig.py index 207d94468..774e3b44c 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEM.py +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.py @@ -18,4 +18,11 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libParaMEDMEM_Swig import * +print """ +********************************************************************** +********************************************************************** +libMEDLoader_Swig module DEPRECATED ! +Please use instead \"import MEDLoader\" or \"from MEDLoader import *\" +********************************************************************** +********************************************************************** +""" diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 6dadebf48..83bb4c6ac 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -330,6 +330,18 @@ void MEDLoaderTest::testMultiMeshRW1() CPPUNIT_ASSERT(mesh2_2->isEqual(mesh2,1e-12)); mesh2_2->decrRef(); // + std::vector ret=MEDLoader::GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"); + CPPUNIT_ASSERT_EQUAL(4,(int)ret.size()); + CPPUNIT_ASSERT(ret[0]=="Family_1"); + CPPUNIT_ASSERT(ret[1]=="Family_2"); + CPPUNIT_ASSERT(ret[2]=="Family_3"); + CPPUNIT_ASSERT(ret[3]=="Family_4"); + // + std::vector ret1=MEDLoader::GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2"); + CPPUNIT_ASSERT_EQUAL(2,(int)ret1.size()); + CPPUNIT_ASSERT(ret1[0]=="3DMesh_1"); + CPPUNIT_ASSERT(ret1[1]=="mesh2"); + // mesh4->decrRef(); mesh3->decrRef(); mesh2->decrRef(); @@ -934,7 +946,7 @@ MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2() const double vec[3]={0.,1.,0.}; const double pt[3]={0.,0.,0.}; m1d->rotate(pt,vec,-M_PI/2.); - MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMeshFromThis(m1d,0); + MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMesh(m1d,0); m1d->decrRef(); m3dsurf->decrRef(); return ret; diff --git a/src/ParaMEDMEM/ICoCoMEDField.cxx b/src/ParaMEDMEM/ICoCoMEDField.cxx index cc3b61dd5..f3f9e66a0 100644 --- a/src/ParaMEDMEM/ICoCoMEDField.cxx +++ b/src/ParaMEDMEM/ICoCoMEDField.cxx @@ -88,6 +88,7 @@ namespace ICoCo //creating a connectivity table that complies to MED (1 indexing) //and passing it to _mesh int* conn=new int[triofield._nodes_per_elem]; + _mesh->setMeshDimension(triofield._mesh_dim); for (int i=0; isetMeshDimension(triofield._mesh_dim); _mesh->finishInsertingCells(); //field on the sending end diff --git a/src/ParaMEDMEM_Swig/Makefile.am b/src/ParaMEDMEM_Swig/Makefile.am index c65f7eace..e1b74305c 100644 --- a/src/ParaMEDMEM_Swig/Makefile.am +++ b/src/ParaMEDMEM_Swig/Makefile.am @@ -21,42 +21,42 @@ # include $(top_srcdir)/adm_local/unix/make_common_starter.am -lib_LTLIBRARIES = _libParaMEDMEM_Swig.la +lib_LTLIBRARIES = _ParaMEDMEM.la salomeinclude_HEADERS = \ - libParaMEDMEM_Swig.i + ParaMEDMEM.i -SWIG_DEF = libParaMEDMEM_Swig.i libParaMEDMEM_Swig.typemap +SWIG_DEF = ParaMEDMEM.i ParaMEDMEM.typemap SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling -I$(srcdir)/../MEDCoupling_Swig \ -I$(srcdir)/../MEDLoader/Swig -I$(srcdir)/../INTERP_KERNEL -I$(srcdir)/../INTERP_KERNEL/Bases -I$(srcdir)/../ParaMEDLoader \ -I$(srcdir)/../MEDLoader -dist__libParaMEDMEM_Swig_la_SOURCES = $(SWIG_DEF) -nodist__libParaMEDMEM_Swig_la_SOURCES = libParaMEDMEM_Swig_wrap.cxx -libParaMEDMEM_Swig.py: libParaMEDMEM_Swig_wrap.cxx +dist__ParaMEDMEM_la_SOURCES = $(SWIG_DEF) +nodist__ParaMEDMEM_la_SOURCES = ParaMEDMEM_wrap.cxx +ParaMEDMEM.py : ParaMEDMEM_wrap.cxx -libParaMEDMEM_Swig_wrap.cxx: $(SWIG_DEF) +ParaMEDMEM_wrap.cxx: $(SWIG_DEF) $(SWIG) $(SWIG_FLAGS) -o $@ $< -_libParaMEDMEM_Swig_la_CPPFLAGS = $(PYTHON_INCLUDES) \ +_ParaMEDMEM_la_CPPFLAGS = $(PYTHON_INCLUDES) \ $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ $(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling_Swig -I$(srcdir)/../INTERP_KERNEL/Bases \ -I$(srcdir)/../MEDCoupling -I$(srcdir)/../ParaMEDLoader -I$(srcdir)/../MEDLoader -I$(srcdir)/../MEDLoader/Swig -_libParaMEDMEM_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \ +_ParaMEDMEM_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \ ../MEDCoupling/libmedcoupling.la ../INTERP_KERNEL/libinterpkernel.la \ ../ParaMEDMEM/libparamedmem.la ../ParaMEDLoader/libparamedloader.la if MED_ENABLE_KERNEL - _libParaMEDMEM_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS} - _libParaMEDMEM_Swig_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace + _ParaMEDMEM_la_CPPFLAGS += ${KERNEL_CXXFLAGS} + _ParaMEDMEM_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace endif -CLEANFILES = libParaMEDMEM_Swig_wrap.cxx libParaMEDMEM_Swig.py +CLEANFILES = ParaMEDMEM_wrap.cxx ParaMEDMEM.py dist_salomescript_DATA= test_InterpKernelDEC.py \ test_NonCoincidentDEC.py \ - test_StructuredCoincodentDEC.py \ - ParaMEDMEM.py libParaMEDMEM_Swig.py + test_StructuredCoincidentDEC.py \ + ParaMEDMEM.py diff --git a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i b/src/ParaMEDMEM_Swig/ParaMEDMEM.i similarity index 98% rename from src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i rename to src/ParaMEDMEM_Swig/ParaMEDMEM.i index 21ccd0aa8..0462d0293 100644 --- a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.i @@ -17,11 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -%module libParaMEDMEM_Swig +%module ParaMEDMEM -%include "libParaMEDMEM_Swig.typemap" -%include "libMEDCoupling_Swig.i" -%include "libMEDLoader_Swig.i" +%include "ParaMEDMEM.typemap" +%include "MEDCoupling.i" +%include "MEDLoader.i" %{ #include "CommInterface.hxx" diff --git a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap b/src/ParaMEDMEM_Swig/ParaMEDMEM.typemap similarity index 100% rename from src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap rename to src/ParaMEDMEM_Swig/ParaMEDMEM.typemap diff --git a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py index 2a9a77d29..b436a5189 100755 --- a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py +++ b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py @@ -19,7 +19,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libParaMEDMEM_Swig import * +from ParaMEDMEM import * import sys, os import unittest import math diff --git a/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py similarity index 99% rename from src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py rename to src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py index 95a184e98..a687f0693 100755 --- a/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py +++ b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py @@ -19,7 +19,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from libParaMEDMEM_Swig import * +from ParaMEDMEM import * import sys, os import unittest import math -- 2.39.2