From: vsr Date: Thu, 28 Feb 2013 14:08:57 +0000 (+0000) Subject: Merge from V6_main 28/02/2013 X-Git-Tag: V7_3_1b1~467 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=29f721b8ca46ed5d7872a8a23dd891c46d74ba10;p=tools%2Fmedcoupling.git Merge from V6_main 28/02/2013 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 39e1b2347..a613e771c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,9 @@ SET(VERSION "7.0.0") SET(VERSION_DEV "1") SET(WITH_MEDMEMGUI "0") +#Defining all options first +option(SALOME_USE_MPI "Use MPI containers" OFF) + SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR}) IF(KERNEL_ROOT_DIR) FILE(TO_CMAKE_PATH $ENV{KERNEL_ROOT_DIR} KERNEL_ROOT_DIR) @@ -35,38 +38,42 @@ IF(KERNEL_ROOT_DIR) SET(SALOME_MACROS_DIR ${KERNEL_ROOT_DIR}/salome_adm/cmake_files) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPYTHON.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindMPI.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindHDF5.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindBOOST.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSWIG.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindPLATFORM.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindPYTHON.cmake) + if(SALOME_USE_MPI) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindMPI.cmake) + endif(SALOME_USE_MPI) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindOMNIORB.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindPTHREADS.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindHDF5.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindBOOST.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindLIBXML2.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindSWIG.cmake) INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindDOXYGEN.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindDOXYGEN.cmake) INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSPHINX.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBBATCH.cmake) - INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindKERNEL.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSalomeLIBBATCH.cmake) + INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/FindKERNEL.cmake) SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR}) FILE(TO_CMAKE_PATH $ENV{GUI_ROOT_DIR} GUI_ROOT_DIR) IF(GUI_ROOT_DIR) SET(MED_ENABLE_GUI ON) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindCAS.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQT4.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindOPENGL.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindVTK.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQWT.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake) - INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindGUI.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindCAS.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindQT4.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindOPENGL.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindVTK.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindQWT.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindSIPPYQT.cmake) + INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/deprecated/FindGUI.cmake) ENDIF(GUI_ROOT_DIR) ELSE(KERNEL_ROOT_DIR) SET(SALOME_MACROS_DIR ${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files) INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindPLATFORM.cmake) - INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindMPI.cmake) + if(SALOME_USE_MPI) + INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindMPI.cmake) + endif(SALOME_USE_MPI) INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindBOOST.cmake) INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindCPPUNIT.cmake) INCLUDE(${CMAKE_SOURCE_DIR}/adm_local_without_kernel/cmake_files/FindHDF5.cmake) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index f3b35dd2f..bbecf7655 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -17,7 +17,6 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -ADD_SUBDIRECTORY(MEDMEM) ADD_SUBDIRECTORY(salome) ADD_SUBDIRECTORY(doxygen) diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt index 3556b4e15..89c389e42 100644 --- a/idl/CMakeLists.txt +++ b/idl/CMakeLists.txt @@ -18,7 +18,7 @@ # # Author : Anthony Geay (CEA/DEN) -INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/UseOMNIORB.cmake) +INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/deprecated/UseOMNIORB.cmake) INCLUDE_DIRECTORIES( ${OMNIORB_INCLUDE_DIRS} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d9ebfc851..a87e65412 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,15 +52,19 @@ IF(MPI_IS_OK) ENDIF(MPI_IS_OK) IF(MED_ENABLE_SPLITTER) - SET(COMMON_SUBDIRS ${COMMON_SUBDIRS} MEDPartitioner) - SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} MEDSPLITTER) - IF(SWIG_STATUS) - SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} MEDSPLITTER_Swig) - ENDIF(SWIG_STATUS) + IF(MED_ENABLE_MED3) + SET(COMMON_SUBDIRS ${COMMON_SUBDIRS} MEDPartitioner) + SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} MEDSPLITTER) + IF(SWIG_STATUS) + SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} MEDSPLITTER_Swig) + ENDIF(SWIG_STATUS) + ENDIF(MED_ENABLE_MED3) ENDIF(MED_ENABLE_SPLITTER) IF(MED_ENABLE_RENUMBER) - SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} RENUMBER) + IF(MED_ENABLE_MED3) + SET(OLD_COMMON_SUBDIRS ${OLD_COMMON_SUBDIRS} RENUMBER) + ENDIF(MED_ENABLE_MED3) ENDIF(MED_ENABLE_RENUMBER) IF(MED_ENABLE_KERNEL) diff --git a/src/INTERP_KERNEL/CellModel.cxx b/src/INTERP_KERNEL/CellModel.cxx index 6a027a819..f1d517d57 100644 --- a/src/INTERP_KERNEL/CellModel.cxx +++ b/src/INTERP_KERNEL/CellModel.cxx @@ -113,6 +113,7 @@ namespace INTERP_KERNEL _quadratic=false; _dyn=false; _extruded_type=NORM_ERROR; + _reverse_extruded_type=NORM_ERROR; _linear_type=NORM_ERROR; _quadratic_type=NORM_ERROR; switch(type) @@ -124,7 +125,7 @@ namespace INTERP_KERNEL break; case NORM_SEG2: { - _nb_of_pts=2; _nb_of_sons=2; _dim=1; _extruded_type=NORM_QUAD4; _quadratic_type=NORM_SEG3; _is_simplex=true; _is_extruded=true; + _nb_of_pts=2; _nb_of_sons=2; _dim=1; _extruded_type=NORM_QUAD4; _quadratic_type=NORM_SEG3; _is_simplex=true; _is_extruded=true; _reverse_extruded_type=NORM_POINT1; _sons_type[0]=NORM_POINT1; _sons_type[1]=NORM_POINT1; _sons_con[0][0]=0; _nb_of_sons_con[0]=1; _sons_con[1][0]=1; _nb_of_sons_con[1]=1; @@ -161,7 +162,7 @@ namespace INTERP_KERNEL break; case NORM_HEXA8: { - _nb_of_pts=8; _nb_of_sons=6; _dim=3; _quadratic_type=NORM_HEXA20; _is_simplex=false; _is_extruded=true; + _nb_of_pts=8; _nb_of_sons=6; _dim=3; _quadratic_type=NORM_HEXA20; _is_simplex=false; _is_extruded=true; _reverse_extruded_type=NORM_QUAD4; _sons_type[0]=NORM_QUAD4; _sons_type[1]=NORM_QUAD4; _sons_type[2]=NORM_QUAD4; _sons_type[3]=NORM_QUAD4; _sons_type[4]=NORM_QUAD4; _sons_type[5]=NORM_QUAD4; _sons_con[0][0]=0; _sons_con[0][1]=1; _sons_con[0][2]=2; _sons_con[0][3]=3; _nb_of_sons_con[0]=4; _sons_con[1][0]=4; _sons_con[1][1]=7; _sons_con[1][2]=6; _sons_con[1][3]=5; _nb_of_sons_con[1]=4; @@ -241,7 +242,7 @@ namespace INTERP_KERNEL break; case NORM_PENTA6: { - _nb_of_pts=6; _nb_of_sons=5; _dim=3; _quadratic_type=NORM_PENTA15; _is_simplex=false; _is_extruded=true; + _nb_of_pts=6; _nb_of_sons=5; _dim=3; _quadratic_type=NORM_PENTA15; _is_simplex=false; _is_extruded=true; _reverse_extruded_type=NORM_TRI3; _sons_type[0]=NORM_TRI3; _sons_type[1]=NORM_TRI3; _sons_type[2]=NORM_QUAD4; _sons_type[3]=NORM_QUAD4; _sons_type[4]=NORM_QUAD4; _sons_con[0][0]=0; _sons_con[0][1]=1; _sons_con[0][2]=2; _nb_of_sons_con[0]=3; _sons_con[1][0]=3; _sons_con[1][1]=5; _sons_con[1][2]=4; _nb_of_sons_con[1]=3; diff --git a/src/INTERP_KERNEL/CellModel.hxx b/src/INTERP_KERNEL/CellModel.hxx index 27ec69f05..62c7828ee 100644 --- a/src/INTERP_KERNEL/CellModel.hxx +++ b/src/INTERP_KERNEL/CellModel.hxx @@ -58,6 +58,7 @@ namespace INTERP_KERNEL INTERPKERNEL_EXPORT unsigned getNumberOfNodesConstituentTheSon(unsigned sonId) const { return _nb_of_sons_con[sonId]; } INTERPKERNEL_EXPORT unsigned getNumberOfNodesConstituentTheSon2(unsigned sonId, const int *nodalConn, int lgth) const; INTERPKERNEL_EXPORT NormalizedCellType getExtrudedType() const { return _extruded_type; } + INTERPKERNEL_EXPORT NormalizedCellType getReverseExtrudedType() const { return _reverse_extruded_type; } INTERPKERNEL_EXPORT NormalizedCellType getLinearType() const { return _linear_type; } INTERPKERNEL_EXPORT NormalizedCellType getQuadraticType() const { return _quadratic_type; } INTERPKERNEL_EXPORT NormalizedCellType getSonType(unsigned sonId) const { return _sons_type[sonId]; } @@ -74,6 +75,7 @@ namespace INTERP_KERNEL unsigned _nb_of_sons; NormalizedCellType _type; NormalizedCellType _extruded_type; + NormalizedCellType _reverse_extruded_type; NormalizedCellType _linear_type; NormalizedCellType _quadratic_type; unsigned _sons_con[MAX_NB_OF_SONS][MAX_NB_OF_NODES_PER_ELEM]; diff --git a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.hxx b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.hxx index c045279d2..f63772167 100644 --- a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.hxx +++ b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.hxx @@ -17,8 +17,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef __INTERPKERNELGAUSS_HXX__ -#define __INTERPKERNELGAUSS_HXX__ +#ifndef __INTERPKERNELGAUSSCOORDS_HXX__ +#define __INTERPKERNELGAUSSCOORDS_HXX__ #include "INTERPKERNELDefines.hxx" #include "NormalizedUnstructuredMesh.hxx" @@ -157,4 +157,4 @@ namespace INTERP_KERNEL GaussInfoVector _my_gauss_info; }; } -#endif //INTERPKERNELGAUSS +#endif //INTERPKERNELGAUSSCOORDS diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 875889dad..e2a184545 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -252,6 +252,41 @@ std::set MEDCouplingExtrudedMesh::getAllGeoTy return ret; } +DataArrayInt *MEDCouplingExtrudedMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + INTERP_KERNEL::NormalizedCellType revExtTyp=cm.getReverseExtrudedType(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + if(revExtTyp==INTERP_KERNEL::NORM_ERROR) + { + ret->alloc(0,1); + return ret.retn(); + } + MEDCouplingAutoRefCountObjectPtr tmp=_mesh2D->giveCellsWithType(revExtTyp); + int nbOfLevs=_mesh1D->getNumberOfCells(); + int nbOfCells2D=_mesh2D->getNumberOfCells(); + int nbOfTuples=tmp->getNumberOfTuples(); + ret->alloc(nbOfLevs*nbOfTuples,1); + int *pt=ret->getPointer(); + for(int i=0;ibegin(),tmp->end(),pt,std::bind2nd(std::plus(),i*nbOfCells2D)); + MEDCouplingAutoRefCountObjectPtr ret2=ret->renumberR(_mesh3D_ids->begin()); + ret2->sort(); + return ret2.retn(); +} + +DataArrayInt *MEDCouplingExtrudedMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret2D=_mesh2D->computeNbOfNodesPerCell(); + int nbOfLevs=_mesh1D->getNumberOfCells(); + int nbOfCells2D=_mesh2D->getNumberOfCells(); + MEDCouplingAutoRefCountObjectPtr ret3D=DataArrayInt::New(); ret3D->alloc(nbOfLevs*nbOfCells2D,1); + int *pt=ret3D->getPointer(); + for(int i=0;ibegin(),ret2D->end(),pt); + return ret3D->renumberR(_mesh3D_ids->begin()); +} + int MEDCouplingExtrudedMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const { int ret=0; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 8f9bc9c09..951a591a4 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -55,6 +55,8 @@ namespace ParaMEDMEM DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; std::set getAllGeoTypes() const; + DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; void getNodeIdsOfCell(int cellId, std::vector& conn) const; void getCoordinatesOfNode(int nodeId, std::vector& coo) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index da93e7a6e..7a11d759d 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -395,3 +395,15 @@ int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL: else throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfMeshPlacesExpected : Empty mesh !"); } + +/*! + * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason). + */ +void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception) +{ + if(other) + { + setName(other->_name.c_str()); + setDescription(other->_desc.c_str()); + } +} diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 6dbe8bfdd..06f5f5969 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -50,6 +50,7 @@ namespace ParaMEDMEM virtual bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception); virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + virtual void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); const ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } void setName(const char *name) { _name=name; } diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 461efc9aa..b18ac9978 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,20 @@ const char MEDCouplingFieldDiscretizationKriging::REPR[]="KRIGING"; const TypeOfField MEDCouplingFieldDiscretizationKriging::TYPE=ON_NODES_KR; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG2[2]={1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG3[3]={0.5555555555555556,0.5555555555555556,0.8888888888888888}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG4[4]={0.347854845137454,0.347854845137454,0.652145154862546,0.652145154862546}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI3[3]={0.16666666666666666,0.16666666666666666,0.16666666666666666}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI6[6]={0.0549758718227661,0.0549758718227661,0.0549758718227661,0.11169079483905,0.11169079483905,0.11169079483905}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI7[7]={0.062969590272413,0.062969590272413,0.062969590272413,0.066197076394253,0.066197076394253,0.066197076394253,0.1125}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD4[4]={1.,1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD9[9]={0.30864197530864196,0.30864197530864196,0.30864197530864196,0.30864197530864196,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.7901234567901234}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_TETRA4[4]={0.041666666666666664,0.041666666666666664,0.041666666666666664,0.041666666666666664}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA6[6]={0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA8[8]={1.,1.,1.,1.,1.,1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA27[27]={0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.7023319615912208}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA5[5]={0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333}; + MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION) { } @@ -140,7 +155,7 @@ std::size_t MEDCouplingFieldDiscretization::getHeapMemorySize() const */ void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception) { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,true); + MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,true); int nbOfCompo=arr->getNumberOfComponents(); int nbOfElems=getNumberOfTuples(mesh); std::fill(res,res+nbOfCompo,0.); @@ -155,7 +170,6 @@ void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const D deno+=v; } std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies(),1./deno)); - vol->decrRef(); } /*! @@ -165,7 +179,7 @@ void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const D */ void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception) { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,true); + MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,true); int nbOfCompo=arr->getNumberOfComponents(); int nbOfElems=getNumberOfTuples(mesh); std::fill(res,res+nbOfCompo,0.); @@ -181,7 +195,6 @@ void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const D } std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies(),1./deno)); std::transform(res,res+nbOfCompo,res,std::ptr_fun(std::sqrt)); - vol->decrRef(); } /*! @@ -191,7 +204,7 @@ void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const D */ void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception) { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,isWAbs); + MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,isWAbs); int nbOfCompo=arr->getNumberOfComponents(); int nbOfElems=getNumberOfTuples(mesh); std::fill(res,res+nbOfCompo,0.); @@ -204,7 +217,6 @@ void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const std::transform(tmp,tmp+nbOfCompo,res,res,std::plus()); } delete [] tmp; - vol->decrRef(); } void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const @@ -309,7 +321,7 @@ void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, cons int oldNbOfElems=arr->getNumberOfTuples(); int nbOfComp=arr->getNumberOfComponents(); int newNbOfTuples=newNbOfEntity; - DataArrayDouble *arrCpy=arr->deepCpy(); + MEDCouplingAutoRefCountObjectPtr arrCpy=arr->deepCpy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(newNbOfTuples); double *ptToFill=arr->getPointer(); @@ -330,7 +342,6 @@ void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, cons //if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp)) if(*std::max_element((double *)tmp,((double *)tmp)+nbOfComp)>eps) { - arrCpy->decrRef(); std::ostringstream oss; oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr << " have been merged and " << msg << " field on them are different !"; @@ -339,13 +350,12 @@ void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, cons } } } - arrCpy->decrRef(); } void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) { int nbOfComp=arr->getNumberOfComponents(); - DataArrayDouble *arrCpy=arr->deepCpy(); + MEDCouplingAutoRefCountObjectPtr arrCpy=arr->deepCpy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(new2OldSz); double *ptToFill=arr->getPointer(); @@ -354,7 +364,6 @@ void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2O int oldNb=new2OldPtr[i]; std::copy(ptSrc+oldNb*nbOfComp,ptSrc+(oldNb+1)*nbOfComp,ptToFill+i*nbOfComp); } - arrCpy->decrRef(); } MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization() @@ -1593,6 +1602,90 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscVal throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception) +{ + if(!mesh || !arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !"); + int nbOfCompo=arr->getNumberOfComponents(); + std::fill(res,res+nbOfCompo,0.); + // + MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,isWAbs); + std::set types=mesh->getAllGeoTypes(); + MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); + nbOfNodesPerCell->computeOffsets2(); + const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin(); + for(std::set::const_iterator it=types.begin();it!=types.end();it++) + { + std::size_t wArrSz=-1; + const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz); + INTERP_KERNEL::AutoPtr wArr2=new double[wArrSz]; + double sum=std::accumulate(wArr,wArr+wArrSz,0.); + std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies(),1./sum)); + MEDCouplingAutoRefCountObjectPtr ids=mesh->giveCellsWithType(*it); + MEDCouplingAutoRefCountObjectPtr ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell); + const int *ptIds2=ids2->begin(),*ptIds=ids->begin(); + int nbOfCellsWithCurGeoType=ids->getNumberOfTuples(); + for(int i=0;i umesh=mesh->buildUnstructured(); - MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=umesh->computeNbOfNodesPerCell(); + MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); nbOfNodesPerCell->computeOffsets2(); MEDCouplingAutoRefCountObjectPtr sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1); return sel->buildExplicitArrByRanges(nbOfNodesPerCell); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 8e194911f..c4930dc01 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -286,6 +286,7 @@ namespace ParaMEDMEM void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; + void integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception); void computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, DataArrayInt *&cellRest); void checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception); @@ -300,11 +301,29 @@ namespace ParaMEDMEM void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; + static const double *GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception); protected: MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other); public: static const char REPR[]; static const TypeOfField TYPE; + static const double FGP_SEG2[2]; + static const double FGP_SEG3[3]; + static const double FGP_SEG4[4]; + static const double FGP_TRI3[3]; + static const double FGP_TRI6[6]; + static const double FGP_TRI7[7]; + static const double FGP_QUAD4[4]; + //static const double FGP_QUAD8[8]; + static const double FGP_QUAD9[9]; + static const double FGP_TETRA4[4]; + //static const double FGP_TETRA10[10]; + static const double FGP_PENTA6[6]; + //static const double FGP_PENTA15[15]; + static const double FGP_HEXA8[8]; + static const double FGP_HEXA27[27]; + static const double FGP_PYRA5[5]; + //static const double FGP_PYRA13[13]; }; class MEDCOUPLING_EXPORT MEDCouplingFieldDiscretizationKriging : public MEDCouplingFieldDiscretizationOnNodes diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index f2fb7e1bd..03d44c8d0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -176,13 +176,13 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfT /*! * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason). */ -void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception) { - if(other) + MEDCouplingField::copyTinyStringsFrom(other); + const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + if(otherC) { - setName(other->_name.c_str()); - setDescription(other->_desc.c_str()); - _time_discr->copyTinyStringsFrom(*other->_time_discr); + _time_discr->copyTinyStringsFrom(*otherC->_time_discr); } } @@ -196,6 +196,13 @@ void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *othe { _time_discr->copyTinyAttrFrom(*other->_time_discr); } + +} + +void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception) +{ + copyTinyStringsFrom(other); + copyTinyAttrFrom(other); } std::string MEDCouplingFieldDouble::simpleRepr() const diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 3b275f9de..da5e01ba0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -38,8 +38,9 @@ namespace ParaMEDMEM void setTimeUnit(const char *unit); const char *getTimeUnit() const; void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception); - void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 4436fa7d1..a49ba2d8d 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -360,13 +360,13 @@ void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *m { if(value!=start || end!=start) { - std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected start " << start << " of range in [0," << value << "[ !"; + std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg << " ! Expected start " << start << " of input range, in [0," << value << "[ !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } if(end<0 || end>value) { - std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected start " << end << " of range in [0," << value << "[ !"; + std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg << " ! Expected end " << end << " of input range, in [0," << value << "] !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -375,7 +375,7 @@ void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) thro { if(value<0 || value>ref) { - std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << "] having closing open parenthesis " << value << " !"; + std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected input range in [0," << ref << "] having closing open parenthesis " << value << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -584,12 +584,26 @@ void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception) throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !"); } +void DataArrayDouble::pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception) +{ + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) + _mem.insertAtTheEnd(valsBg,valsEnd); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.insertAtTheEnd(valsBg,valsEnd); + } + else + throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !"); +} + double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) return _mem.popBack(); else - throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::popBackSilent : not available for DataArrayDouble with number of components different than 1 !"); } void DataArrayDouble::pack() const throw(INTERP_KERNEL::Exception) @@ -847,7 +861,7 @@ DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::E DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception) { if(_mem.isNull()) - throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !"); double *tab=_mem.toNoInterlace(getNumberOfComponents()); DataArrayDouble *ret=DataArrayDouble::New(); ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents()); @@ -860,6 +874,7 @@ DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exc */ void DataArrayDouble::renumberInPlace(const int *old2New) { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); double *tmp=new double[nbTuples*nbOfCompo]; @@ -877,6 +892,7 @@ void DataArrayDouble::renumberInPlace(const int *old2New) */ void DataArrayDouble::renumberInPlaceR(const int *new2Old) { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); double *tmp=new double[nbTuples*nbOfCompo]; @@ -894,6 +910,7 @@ void DataArrayDouble::renumberInPlaceR(const int *new2Old) */ DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayDouble *ret=DataArrayDouble::New(); @@ -913,6 +930,7 @@ DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const */ DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayDouble *ret=DataArrayDouble::New(); @@ -934,6 +952,7 @@ DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const */ DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayDouble *ret=DataArrayDouble::New(); @@ -956,7 +975,8 @@ DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newN */ DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { - DataArrayDouble *ret=DataArrayDouble::New(); + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbComp=getNumberOfComponents(); ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp); ret->copyStringInfoFrom(*this); @@ -966,7 +986,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const in for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++) std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp); ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -974,6 +994,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const in */ DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbComp=getNumberOfComponents(); int oldNbOfTuples=getNumberOfTuples(); @@ -1001,6 +1022,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, cons */ DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbComp=getNumberOfComponents(); int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayDouble::selectByTupleId2 : "); @@ -1080,6 +1102,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector c(c0),cI(cI0); @@ -1311,10 +1335,11 @@ void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std: { if(!a) throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !"); + checkAllocated(); copyPartOfStringInfoFrom2(compoIds,*a); std::size_t partOfCompoSz=compoIds.size(); int nbOfCompo=getNumberOfComponents(); - int nbOfTuples=getNumberOfTuples(); + int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples()); const double *ac=a->getConstPointer(); double *nc=getPointer(); for(int i=0;icheckNbOfElems(newNbOfTuples*newNbOfComp,msg); - if(strictCompoCompare) - a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); - double *pt=getPointer()+bgTuples*nbComp+bgComp; + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } const double *srcPt=a->getConstPointer(); - for(int i=0;icheckAllocated(); + int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg); + int newNbOfComp=(int)std::distance(bgComp,endComp); + int nbComp=getNumberOfComponents(); + for(const int *z=bgComp;z!=endComp;z++) + DataArray::CheckValueInRange(nbComp,*z,"invalid component id"); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + const double *srcPt=a->getConstPointer(); + double *pt=getPointer()+bgTuples*nbComp; + if(assignTech) + { + for(int i=0;icheckAllocated(); @@ -1786,6 +1891,7 @@ void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, do { if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !"); + checkAllocated(); MEDCouplingAutoRefCountObjectPtr bbox=computeBBoxPerTuple(eps); other->checkAllocated(); int nbOfCompo=getNumberOfComponents(); @@ -1845,6 +1951,7 @@ void DataArrayDouble::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::E double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !"); int nbOfTuples=getNumberOfTuples(); @@ -1877,6 +1984,7 @@ double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !"); int nbOfTuples=getNumberOfTuples(); @@ -2001,7 +2109,7 @@ double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Except const double *ptr=getConstPointer(); int nbTuple=getNumberOfTuples(); int nbComps=getNumberOfComponents(); - if(compId>=nbComps) + if(compId<0 || compId>=nbComps) throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !"); double ret=0.; for(int i=0;i(fabs)); + declareAsNew(); } void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception) @@ -2675,6 +2793,7 @@ DataArrayDoubleIterator *DataArrayDouble::iterator() DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !"); const double *cptr=getConstPointer(); @@ -2945,6 +3064,8 @@ void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !"; + checkAllocated(); + other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -3042,6 +3163,8 @@ void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_ if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !"; + checkAllocated(); + other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -3154,6 +3277,8 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !"; + checkAllocated(); + other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -3251,6 +3376,8 @@ void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KER if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !"; + checkAllocated(); + other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -3586,12 +3713,26 @@ void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception) throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !"); } +void DataArrayInt::pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception) +{ + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) + _mem.insertAtTheEnd(valsBg,valsEnd); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.insertAtTheEnd(valsBg,valsEnd); + } + else + throw INTERP_KERNEL::Exception("DataArrayInt::pushBackValsSilent : not available for DataArrayInt with number of components different than 1 !"); +} + int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) return _mem.popBack(); else - throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !"); + throw INTERP_KERNEL::Exception("DataArrayInt::popBackSilent : not available for DataArrayInt with number of components different than 1 !"); } void DataArrayInt::pack() const throw(INTERP_KERNEL::Exception) @@ -3661,6 +3802,7 @@ std::string DataArrayInt::reprZip() const void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); std::string idt(indent,' '); ofs << idt << "\n" << idt; @@ -3718,6 +3860,7 @@ void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) cons */ void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !"); int nbElemsIn=(int)std::distance(indArrBg,indArrEnd); @@ -3756,6 +3899,7 @@ void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd, DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("Call splitByValueRange method on DataArrayInt with only one component, you can call 'rearrange' method before !"); int nbOfTuples=getNumberOfTuples(); @@ -3804,11 +3948,12 @@ void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd, * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v on place i, place indArr[v] will have * value i. * indArr[v] where 'indArr' is defined by ['indArrBg','indArrEnd'). - * This method is half/safe that is to say if there is location i so that indArr[v] is not in [0,this->getNumberOfTuples()) an exception - * will be thrown. + * This method is safe that is to say if there is location i so that indArr[v] is not in [0,this->getNumberOfTuples()) an exception + * will be thrown. An exception is also thrown if there is a location i so that \a this[i] not in [0,distance(indArrBg,indArrEnd)) ! */ DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !"); int nbElemsIn=(int)std::distance(indArrBg,indArrEnd); @@ -3820,12 +3965,20 @@ DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int int *tmp=ret->getPointer(); for(int i=0;i=0 && pos=0 && *pt=0 && pos ret=DataArrayInt::New(); ret->alloc(newNbOfElem,1); int nbOfOldNodes=getNumberOfTuples(); const int *old2New=getConstPointer(); @@ -3846,7 +3999,7 @@ DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const for(int i=0;i!=nbOfOldNodes;i++) if(old2New[i]!=-1) pt[old2New[i]]=i; - return ret; + return ret.retn(); } /*! @@ -3855,7 +4008,7 @@ DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const */ DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(newNbOfElem,1); int nbOfOldNodes=getNumberOfTuples(); const int *old2New=getConstPointer(); @@ -3863,7 +4016,7 @@ DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(I for(int i=nbOfOldNodes-1;i>=0;i--) if(old2New[i]!=-1) pt[old2New[i]]=i; - return ret; + return ret.retn(); } /*! @@ -3871,7 +4024,8 @@ DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(I */ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const { - DataArrayInt *ret=DataArrayInt::New(); + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(oldNbOfElem,1); const int *new2Old=getConstPointer(); int *pt=ret->getPointer(); @@ -3879,7 +4033,7 @@ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const int nbOfNewElems=getNumberOfTuples(); for(int i=0;i ret=DataArrayInt::New(); @@ -4078,6 +4234,7 @@ void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(_mem.isNull()) throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !"); int *tab=_mem.fromNoInterlace(getNumberOfComponents()); @@ -4088,6 +4245,7 @@ DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Excepti DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(_mem.isNull()) throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !"); int *tab=_mem.toNoInterlace(getNumberOfComponents()); @@ -4098,6 +4256,7 @@ DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception void DataArrayInt::renumberInPlace(const int *old2New) { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); int *tmp=new int[nbTuples*nbOfCompo]; @@ -4111,6 +4270,7 @@ void DataArrayInt::renumberInPlace(const int *old2New) void DataArrayInt::renumberInPlaceR(const int *new2Old) { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); int *tmp=new int[nbTuples*nbOfCompo]; @@ -4129,6 +4289,7 @@ void DataArrayInt::renumberInPlaceR(const int *new2Old) */ DataArrayInt *DataArrayInt::renumber(const int *old2New) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayInt *ret=DataArrayInt::New(); @@ -4144,6 +4305,7 @@ DataArrayInt *DataArrayInt::renumber(const int *old2New) const DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayInt *ret=DataArrayInt::New(); @@ -4165,6 +4327,7 @@ DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const */ DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const { + checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); DataArrayInt *ret=DataArrayInt::New(); @@ -4187,7 +4350,8 @@ DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTup */ DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { - DataArrayInt *ret=DataArrayInt::New(); + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); int nbComp=getNumberOfComponents(); ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp); ret->copyStringInfoFrom(*this); @@ -4197,7 +4361,7 @@ DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++) std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp); ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -4205,6 +4369,7 @@ DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new */ DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); int nbComp=getNumberOfComponents(); int oldNbOfTuples=getNumberOfTuples(); @@ -4232,6 +4397,7 @@ DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int */ DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); int nbComp=getNumberOfComponents(); int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); @@ -4256,10 +4422,10 @@ DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector ret=DataArrayInt::New(); ret->alloc(0,nbOfComp); ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } int ref=ranges.front().first; int nbOfTuples=0; @@ -4346,11 +4512,11 @@ void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, Data for(int i=0;i=0 && tmp2& compoIds) throw(INTERP_KERNEL::Exception) { + if(!a) + throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !"); + checkAllocated(); + a->checkAllocated(); copyPartOfStringInfoFrom2(compoIds,*a); std::size_t partOfCompoSz=compoIds.size(); int nbOfCompo=getNumberOfComponents(); - int nbOfTuples=getNumberOfTuples(); + int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples()); const int *ac=a->getConstPointer(); int *nc=getPointer(); for(int i=0;icheckNbOfElems(newNbOfTuples*newNbOfComp,msg); - if(strictCompoCompare) - a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } int *pt=getPointer()+bgTuples*nbComp+bgComp; const int *srcPt=a->getConstPointer(); - for(int i=0;icheckAllocated(); + int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg); + int newNbOfComp=(int)std::distance(bgComp,endComp); + int nbComp=getNumberOfComponents(); + for(const int *z=bgComp;z!=endComp;z++) + DataArray::CheckValueInRange(nbComp,*z,"invalid component id"); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + const int *srcPt=a->getConstPointer(); + int *pt=getPointer()+bgTuples*nbComp; + if(assignTech) + { + for(int i=0;icheckAllocated(); @@ -5035,6 +5286,7 @@ DataArrayIntIterator *DataArrayInt::iterator() DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); const int *cptr=getConstPointer(); @@ -5048,6 +5300,7 @@ DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exce DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !"); const int *cptr=getConstPointer(); @@ -5067,9 +5320,9 @@ DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::E */ int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !"); - checkAllocated(); int *start=getPointer(); int *end2=start+getNbOfElems(); int ret=0; @@ -5132,6 +5385,7 @@ DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *val */ int DataArrayInt::locateTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); int nbOfCompo=getNumberOfComponents(); if(nbOfCompo==0) throw INTERP_KERNEL::Exception("DataArrayInt::locateTuple : 0 components in 'this' !"); @@ -5164,6 +5418,7 @@ int DataArrayInt::locateTuple(const std::vector& tupl) const throw(INTERP_K */ int DataArrayInt::search(const std::vector& vals) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); int nbOfCompo=getNumberOfComponents(); if(nbOfCompo!=1) throw INTERP_KERNEL::Exception("DataArrayInt::search : works only for DataArrayInt instance with one component !"); @@ -5183,6 +5438,7 @@ int DataArrayInt::search(const std::vector& vals) const throw(INTERP_KERNEL */ int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); const int *cptr=getConstPointer(); @@ -5201,6 +5457,7 @@ int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception) */ int DataArrayInt::locateValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); std::set vals2(vals.begin(),vals.end()); @@ -5265,7 +5522,7 @@ int DataArrayInt::accumulate(int compId) const throw(INTERP_KERNEL::Exception) const int *ptr=getConstPointer(); int nbTuple=getNumberOfTuples(); int nbComps=getNumberOfComponents(); - if(compId>=nbComps) + if(compId<0 || compId>=nbComps) throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !"); int ret=0; for(int i=0;i& a int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !"); int nbOfTuples=getNumberOfTuples(); @@ -5341,6 +5599,7 @@ int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception) int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !"); int nbOfTuples=getNumberOfTuples(); @@ -5368,6 +5627,7 @@ void DataArrayInt::abs() throw(INTERP_KERNEL::Exception) int *ptr=getPointer(); int nbOfElems=getNbOfElems(); std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(std::abs)); + declareAsNew(); } void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception) @@ -5467,6 +5727,7 @@ void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception) */ DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !"); const int *cptr=getConstPointer(); @@ -5661,12 +5922,12 @@ DataArrayInt *DataArrayInt::BuildIntersection(const std::vectorcheckAllocated(); if((*it)->getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !"); + throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !"); int tmp1; valm=std::min((*it)->getMinValue(tmp1),valm); } if(valm<0) - throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !"); + throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : a negative value has been detected !"); // std::set r; for(std::vector::const_iterator it=a.begin();it!=a.end();it++) @@ -6183,6 +6444,7 @@ void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exce if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual !"; + checkAllocated(); other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -6280,6 +6542,7 @@ void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual !"; + checkAllocated(); other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -6387,6 +6650,7 @@ void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL: if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !"; + checkAllocated(); other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -6484,6 +6748,7 @@ void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::E if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !"; + checkAllocated(); other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); @@ -6581,6 +6846,7 @@ void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL:: if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::modulusEqual : input DataArrayInt instance is NULL !"); const char *msg="Nb of tuples mismatch for DataArrayInt::modulusEqual !"; + checkAllocated(); other->checkAllocated(); int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); int nbOfComp=getNumberOfComponents(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index eaa272724..115ad548f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -168,6 +168,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reserve(int nbOfElems) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackSilent(double val) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); } @@ -222,6 +223,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues4(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple4(double a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); @@ -373,6 +376,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reserve(int nbOfElems) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackSilent(int val) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); } @@ -440,6 +444,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues4(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 9f86a7445..bf508c8eb 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -84,6 +84,8 @@ namespace ParaMEDMEM virtual int getMeshDimension() const = 0; virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; virtual DataArrayDouble *getBarycenterAndOwner() const = 0; + virtual DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) = 0; virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0; virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; virtual std::set getAllGeoTypes() const = 0; diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 0e120ce10..033fe91b2 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -138,7 +138,7 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFiel if(_src_method!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(_target_method.c_str()),srcField->getTimeDiscretization()); - ret->copyTinyAttrFrom(srcField); + ret->copyAllTinyAttrFrom(srcField); ret->setNature(srcField->getNature()); ret->setMesh(_target_mesh); transfer(srcField,ret,dftValue); @@ -149,8 +149,8 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::reverseTransferField(const MEDCoupl { if(_target_method!=targetField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); - MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(_target_method.c_str()),targetField->getTimeDiscretization()); - ret->copyTinyAttrFrom(targetField); + MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(MEDCouplingFieldDiscretization::getTypeOfFieldFromStringRepr(_src_method.c_str()),targetField->getTimeDiscretization()); + ret->copyAllTinyAttrFrom(targetField); ret->setNature(targetField->getNature()); ret->setMesh(_src_mesh); reverseTransfer(ret,targetField,dftValue); diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 4d02d732b..f473cf7bd 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -71,45 +71,42 @@ INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::getTypeOfCell(int c std::set MEDCouplingStructuredMesh::getAllGeoTypes() const { - INTERP_KERNEL::NormalizedCellType ret; - switch(getMeshDimension()) - { - case 3: - ret=INTERP_KERNEL::NORM_HEXA8; - break; - case 2: - ret=INTERP_KERNEL::NORM_QUAD4; - break; - case 1: - ret=INTERP_KERNEL::NORM_SEG2; - break; - default: - throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingStructuredMesh::getAllGeoTypes !"); - } std::set ret2; - ret2.insert(ret); + ret2.insert(getTypeOfCell(0)); return ret2; } int MEDCouplingStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const { int ret=getNumberOfCells(); - int dim=getMeshDimension(); - switch(type) + if(type==getTypeOfCell(0)) + return ret; + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0)); + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getNumberOfCellsWithType : no specified type ! Type available is " << cm.getRepr() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + if(getTypeOfCell(0)==type) { - case INTERP_KERNEL::NORM_HEXA8: - if(dim==3) - return ret; - case INTERP_KERNEL::NORM_QUAD4: - if(dim==2) - return ret; - case INTERP_KERNEL::NORM_SEG2: - if(dim==1) - return ret; - default: - throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingStructuredMesh::getTypeOfCell !"); + ret->alloc(getNumberOfCells(),1); + ret->iota(0); } - return 0; + else + ret->alloc(0,1); + return ret.retn(); +} + +DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +{ + int nbCells=getNumberOfCells(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(nbCells,1); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0)); + ret->fillWithValue((int)cm.getNumberOfNodes()); + return ret.retn(); } void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx index 80f18ec9f..786d4d2d5 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx @@ -32,6 +32,8 @@ namespace ParaMEDMEM INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; std::set getAllGeoTypes() const; int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; + DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); static void GetPosFromId(int nodeId, int meshDim, const int *split, int *res); void getNodeIdsOfCell(int cellId, std::vector& conn) const; std::size_t getHeapMemorySize() const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index a34d71b80..8443998f0 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1989,7 +1989,7 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const DataArrayInt *revDesc=DataArrayInt::New(); DataArrayInt *revDescIndx=DataArrayInt::New(); // - MEDCouplingUMesh *meshDM1=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + MEDCouplingAutoRefCountObjectPtr meshDM1=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); revDesc->decrRef(); desc->decrRef(); descIndx->decrRef(); @@ -2001,7 +2001,6 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const boundaryCells.push_back(i); revDescIndx->decrRef(); MEDCouplingPointSet *ret=meshDM1->buildPartOfMySelf(&boundaryCells[0],&boundaryCells[0]+boundaryCells.size(),keepCoords); - meshDM1->decrRef(); return ret; } @@ -2906,15 +2905,13 @@ void MEDCouplingUMesh::unserialization(const std::vector& tinyInfoD, con { // Connectivity const int *recvBuffer=a1->getConstPointer(); - DataArrayInt* myConnecIndex=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr myConnecIndex=DataArrayInt::New(); myConnecIndex->alloc(tinyInfo[6]+1,1); std::copy(recvBuffer,recvBuffer+tinyInfo[6]+1,myConnecIndex->getPointer()); - DataArrayInt* myConnec=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr myConnec=DataArrayInt::New(); myConnec->alloc(tinyInfo[7],1); std::copy(recvBuffer+tinyInfo[6]+1,recvBuffer+tinyInfo[6]+1+tinyInfo[7],myConnec->getPointer()); - setConnectivity(myConnec, myConnecIndex) ; - myConnec->decrRef(); - myConnecIndex->decrRef(); + setConnectivity(myConnec, myConnecIndex); } } @@ -2999,14 +2996,12 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin types.insert((INTERP_KERNEL::NormalizedCellType)conn[connIndex[*work]]); connRetWork=std::copy(conn+connIndex[*work],conn+connIndex[*work+1],connRetWork); } - DataArrayInt *connRetArr=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr connRetArr=DataArrayInt::New(); connRetArr->useArray(connRet,true,CPP_DEALLOC,connIndexRet[nbOfElemsRet],1); - DataArrayInt *connIndexRetArr=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr connIndexRetArr=DataArrayInt::New(); connIndexRetArr->useArray(connIndexRet,true,CPP_DEALLOC,(int)nbOfElemsRet+1,1); ret->setConnectivity(connRetArr,connIndexRetArr,false); ret->_types=types; - connRetArr->decrRef(); - connIndexRetArr->decrRef(); ret->copyTinyInfoFrom(this); return ret.retn(); } @@ -3025,13 +3020,12 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureField(bool isAbs) const std::string name="MeasureOfMesh_"; name+=getName(); int nbelem=getNumberOfCells(); - MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + MEDCouplingAutoRefCountObjectPtr field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); field->setName(name.c_str()); - DataArrayDouble* array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); array->alloc(nbelem,1); double *area_vol=array->getPointer(); - field->setArray(array) ; - array->decrRef(); + field->setArray(array) ; array=0; field->setMesh(const_cast(this)); field->synchronizeTimeWithMesh(); if(getMeshDimension()!=-1) @@ -3055,7 +3049,7 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureField(bool isAbs) const { area_vol[0]=std::numeric_limits::max(); } - return field; + return field.retn(); } /*! @@ -3067,7 +3061,7 @@ DataArrayDouble *MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *be std::string name="PartMeasureOfMesh_"; name+=getName(); int nbelem=(int)std::distance(begin,end); - DataArrayDouble* array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); array->setName(name.c_str()); array->alloc(nbelem,1); double *area_vol=array->getPointer(); @@ -3092,7 +3086,7 @@ DataArrayDouble *MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *be { area_vol[0]=std::numeric_limits::max(); } - return array; + return array.retn(); } /*! @@ -3101,19 +3095,19 @@ DataArrayDouble *MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *be */ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) const { - MEDCouplingFieldDouble *tmp=getMeasureField(isAbs); + MEDCouplingAutoRefCountObjectPtr tmp=getMeasureField(isAbs); std::string name="MeasureOnNodeOfMesh_"; name+=getName(); int nbNodes=getNumberOfNodes(); - MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_NODES); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_NODES); double cst=1./((double)getMeshDimension()+1.); - DataArrayDouble* array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); array->alloc(nbNodes,1); double *valsToFill=array->getPointer(); std::fill(valsToFill,valsToFill+nbNodes,0.); const double *values=tmp->getArray()->getConstPointer(); - DataArrayInt *da=DataArrayInt::New(); - DataArrayInt *daInd=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr da=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr daInd=DataArrayInt::New(); getReverseNodalConnectivity(da,daInd); const int *daPtr=da->getConstPointer(); const int *daIPtr=daInd->getConstPointer(); @@ -3121,12 +3115,8 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons for(const int *cell=daPtr+daIPtr[i];cell!=daPtr+daIPtr[i+1];cell++) valsToFill[i]+=cst*values[*cell]; ret->setMesh(this); - da->decrRef(); - daInd->decrRef(); ret->setArray(array); - array->decrRef(); - tmp->decrRef(); - return ret; + return ret.retn(); } /*! @@ -3137,8 +3127,8 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const { 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,ONE_TIME); - DataArrayDouble *array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); int nbOfCells=getNumberOfCells(); int nbComp=getMeshDimension()+1; array->alloc(nbOfCells,nbComp); @@ -3150,7 +3140,7 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const { if(getSpaceDimension()==3) { - DataArrayDouble *loc=getBarycenterAndOwner(); + MEDCouplingAutoRefCountObjectPtr loc=getBarycenterAndOwner(); const double *locPtr=loc->getConstPointer(); for(int i=0;i(vals); std::transform(vals,vals+3,vals,std::bind2nd(std::multiplies(),1./n)); } - loc->decrRef(); } else { @@ -3181,10 +3170,9 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const } } ret->setArray(array); - array->decrRef(); ret->setMesh(this); ret->synchronizeTimeWithSupport(); - return ret; + return ret.retn(); } /*! @@ -3195,8 +3183,8 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *be { 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,ONE_TIME); - DataArrayDouble *array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); std::size_t nbelems=std::distance(begin,end); int nbComp=getMeshDimension()+1; array->alloc((int)nbelems,nbComp); @@ -3208,7 +3196,7 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *be { if(getSpaceDimension()==3) { - DataArrayDouble *loc=getPartBarycenterAndOwner(begin,end); + MEDCouplingAutoRefCountObjectPtr loc=getPartBarycenterAndOwner(begin,end); const double *locPtr=loc->getConstPointer(); for(const int *i=begin;i!=end;i++,vals+=3,locPtr+=3) { @@ -3217,7 +3205,6 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *be double n=INTERP_KERNEL::norm<3>(vals); std::transform(vals,vals+3,vals,std::bind2nd(std::multiplies(),1./n)); } - loc->decrRef(); } else { @@ -3239,10 +3226,9 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *be } } ret->setArray(array); - array->decrRef(); ret->setMesh(this); ret->synchronizeTimeWithSupport(); - return ret; + return ret.retn(); } /*! @@ -3255,8 +3241,8 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildDirectionVectorField() const throw INTERP_KERNEL::Exception("Expected a umesh with meshDim == 1 for buildDirectionVectorField !"); if(_types.size()!=1 || *(_types.begin())!=INTERP_KERNEL::NORM_SEG2) throw INTERP_KERNEL::Exception("Expected a umesh with only NORM_SEG2 type of elements for buildDirectionVectorField !"); - MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); - DataArrayDouble *array=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + MEDCouplingAutoRefCountObjectPtr array=DataArrayDouble::New(); int nbOfCells=getNumberOfCells(); int spaceDim=getSpaceDimension(); array->alloc(nbOfCells,spaceDim); @@ -3271,10 +3257,9 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildDirectionVectorField() const pt=std::transform(coo+conn[1]*spaceDim,coo+(conn[1]+1)*spaceDim,coo+conn[0]*spaceDim,pt,std::minus()); } ret->setArray(array); - array->decrRef(); ret->setMesh(this); ret->synchronizeTimeWithSupport(); - return ret; + return ret.retn(); } /*! @@ -3494,7 +3479,7 @@ void MEDCouplingUMesh::project1D(const double *pt, const double *v, double eps, throw INTERP_KERNEL::Exception("Expected a umesh with only NORM_SEG2 type of elements for project1D !"); if(getSpaceDimension()!=3) throw INTERP_KERNEL::Exception("Expected a umesh with spaceDim==3 for project1D !"); - MEDCouplingFieldDouble *f=buildDirectionVectorField(); + MEDCouplingAutoRefCountObjectPtr f=buildDirectionVectorField(); const double *fPtr=f->getArray()->getConstPointer(); double tmp[3]; for(int i=0;i(tmp); n1/=INTERP_KERNEL::norm<3>(tmp1); if(n1>eps) - { - f->decrRef(); - throw INTERP_KERNEL::Exception("UMesh::Projection 1D failed !"); - } + throw INTERP_KERNEL::Exception("UMesh::Projection 1D failed !"); } const double *coo=getCoords()->getConstPointer(); for(int i=0;i()); res[i]=std::accumulate(tmp,tmp+3,0.); } - f->decrRef(); } /*! @@ -3997,7 +3978,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *me } zipCoords(); int oldNbOfNodes=getNumberOfNodes(); - DataArrayDouble *newCoords=0; + MEDCouplingAutoRefCountObjectPtr newCoords; switch(policy) { case 0: @@ -4014,10 +3995,9 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *me throw INTERP_KERNEL::Exception("Not implemented extrusion policy : must be in (0) !"); } setCoords(newCoords); - newCoords->decrRef(); - MEDCouplingUMesh *ret=buildExtrudedMeshFromThisLowLev(oldNbOfNodes,isQuad); + MEDCouplingAutoRefCountObjectPtr ret=buildExtrudedMeshFromThisLowLev(oldNbOfNodes,isQuad); updateTime(); - return ret; + return ret.retn(); } /*! @@ -4160,15 +4140,14 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(con int nbOf1DCells=mesh1D->getNumberOfCells(); if(nbOf1DCells<2) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D : impossible to detect any angle of rotation ! Change extrusion policy 1->0 !"); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbOfLevsInVec=nbOf1DCells+1; ret->alloc(oldNbOfNodes*nbOfLevsInVec,2); double *retPtr=ret->getPointer(); retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr); - MEDCouplingUMesh *tmp=MEDCouplingUMesh::New(); - DataArrayDouble *tmp2=getCoords()->deepCpy(); + MEDCouplingAutoRefCountObjectPtr tmp=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr tmp2=getCoords()->deepCpy(); tmp->setCoords(tmp2); - tmp2->decrRef(); const double *coo1D=mesh1D->getCoords()->getConstPointer(); const int *conn1D=mesh1D->getNodalConnectivity()->getConstPointer(); const int *connI1D=mesh1D->getNodalConnectivityIndex()->getConstPointer(); @@ -4189,8 +4168,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(con tmp->rotate(end,0,angle); retPtr=std::copy(tmp2->getConstPointer(),tmp2->getConstPointer()+tmp2->getNbOfElems(),retPtr); } - tmp->decrRef(); - return ret; + return ret.retn(); } /*! @@ -4206,15 +4184,14 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(con int nbOf1DCells=mesh1D->getNumberOfCells(); if(nbOf1DCells<2) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D : impossible to detect any angle of rotation ! Change extrusion policy 1->0 !"); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbOfLevsInVec=nbOf1DCells+1; ret->alloc(oldNbOfNodes*nbOfLevsInVec,3); double *retPtr=ret->getPointer(); retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr); - MEDCouplingUMesh *tmp=MEDCouplingUMesh::New(); - DataArrayDouble *tmp2=getCoords()->deepCpy(); + MEDCouplingAutoRefCountObjectPtr tmp=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr tmp2=getCoords()->deepCpy(); tmp->setCoords(tmp2); - tmp2->decrRef(); const double *coo1D=mesh1D->getCoords()->getConstPointer(); const int *conn1D=mesh1D->getNodalConnectivity()->getConstPointer(); const int *connI1D=mesh1D->getNodalConnectivityIndex()->getConstPointer(); @@ -4258,8 +4235,7 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(con } retPtr=std::copy(tmp2->getConstPointer(),tmp2->getConstPointer()+tmp2->getNbOfElems(),retPtr); } - tmp->decrRef(); - return ret; + return ret.retn(); } /*! @@ -4276,8 +4252,8 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNode MEDCouplingUMesh *ret=MEDCouplingUMesh::New("Extruded",getMeshDimension()+1); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); - DataArrayInt *newConn=DataArrayInt::New(); - DataArrayInt *newConnI=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr newConn=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr newConnI=DataArrayInt::New(); newConnI->alloc(nbOf3DCells+1,1); int *newConnIPtr=newConnI->getPointer(); *newConnIPtr++=0; @@ -4310,8 +4286,6 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNode } } ret->setConnectivity(newConn,newConnI,true); - newConn->decrRef(); - newConnI->decrRef(); ret->setCoords(getCoords()); return ret; } @@ -4384,7 +4358,7 @@ void MEDCouplingUMesh::convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exce _types.clear(); for(int i=0;i types; + checkFullyDefined(); + MEDCouplingAutoRefCountObjectPtr ret,connSafe,connISafe; + MEDCouplingAutoRefCountObjectPtr coordsSafe; + int meshDim=getMeshDimension(); + switch(conversionType) + { + case 0: + switch(meshDim) + { + case 1: + ret=convertLinearCellsToQuadratic1D0(conn,connI,coords,types); + connSafe=conn; connISafe=connI; coordsSafe=coords; + case 2: + ret=convertLinearCellsToQuadratic2D0(conn,connI,coords,types); + connSafe=conn; connISafe=connI; coordsSafe=coords; + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertLinearCellsToQuadratic : conversion of type 0 mesh dimensions available are [1] !"); + } + //case 1: + //return convertLinearCellsToQuadratic1(); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertLinearCellsToQuadratic : conversion type available are 0 (default, the simplest) and 1 (the most complex) !"); + } + setConnectivity(connSafe,connISafe,false); + _types=types; + setCoords(coordsSafe); + return ret.retn(); +} + +/*! + * Implementes \a conversionType 0 for meshes with meshDim = 1, of MEDCouplingUMesh::convertLinearCellsToQuadratic method. + * \return a newly created DataArrayInt instance that the caller should deal with containing cell ids of converted cells. + * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic. + */ +DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic1D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr bary=getBarycenterAndOwner(); + MEDCouplingAutoRefCountObjectPtr newConn=DataArrayInt::New(); newConn->alloc(0,1); + MEDCouplingAutoRefCountObjectPtr newConnI=DataArrayInt::New(); newConnI->alloc(1,1); newConnI->setIJ(0,0,0); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); + int nbOfCells=getNumberOfCells(); + int nbOfNodes=getNumberOfNodes(); + const int *cPtr=_nodal_connec->getConstPointer(); + const int *icPtr=_nodal_connec_index->getConstPointer(); + int lastVal=0,offset=nbOfNodes; + for(int i=0;ipushBackSilent((int)INTERP_KERNEL::NORM_SEG3); + newConn->pushBackValsSilent(cPtr+cPtr[0]+1,cPtr+cPtr[0]+3); + newConn->pushBackSilent(offset++); + newConnI->pushBackSilent(lastVal+4); + ret->pushBackSilent(i); + lastVal+=4; + } + else + { + types.insert(type); + int tmp=lastVal+(icPtr[1]-icPtr[0]); + newConnI->pushBackSilent(tmp); + newConn->pushBackValsSilent(cPtr+cPtr[0],cPtr+cPtr[1]); + lastVal=tmp; + } + } + MEDCouplingAutoRefCountObjectPtr tmp=bary->selectByTupleIdSafe(ret->begin(),ret->end()); + conn=newConn.retn(); connI=newConnI.retn(); coords=DataArrayDouble::Aggregate(getCoords(),tmp); + return ret.retn(); +} + +/*! + * Implementes \a conversionType 0 for meshes with meshDim = 2, of MEDCouplingUMesh::convertLinearCellsToQuadratic method. + * \return a newly created DataArrayInt instance that the caller should deal with containing cell ids of converted cells. + * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic. + */ +DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic2D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr desc(DataArrayInt::New()),descI(DataArrayInt::New()); + DataArrayInt *tmp2=DataArrayInt::New(),*tmp3=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr m1D=buildDescendingConnectivity2(desc,descI,tmp2,tmp3); tmp2->decrRef(); tmp3->decrRef(); + DataArrayInt *conn1D=0,*conn1DI=0; + std::set types1D; + MEDCouplingAutoRefCountObjectPtr ret1D=m1D->convertLinearCellsToQuadratic1D0(conn1D,conn1DI,coords,types1D); ret1D=0; + return 0;//tony +} + /*! * This method tessallates 'this' so that the number of cells remains the same. * This method works only for meshes with spaceDim equal to 2 and meshDim equal to 2. @@ -5150,11 +5233,10 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getEdgeRatioField() const throw(INTERP MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); ret->setMesh(this); int nbOfCells=getNumberOfCells(); - DataArrayDouble *arr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::New(); arr->alloc(nbOfCells,1); double *pt=arr->getPointer(); ret->setArray(arr);//In case of throw to avoid mem leaks arr will be used after decrRef. - arr->decrRef(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); const double *coo=_coords->getConstPointer(); @@ -5210,11 +5292,10 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getAspectRatioField() const throw(INTE MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); ret->setMesh(this); int nbOfCells=getNumberOfCells(); - DataArrayDouble *arr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::New(); arr->alloc(nbOfCells,1); double *pt=arr->getPointer(); ret->setArray(arr);//In case of throw to avoid mem leaks arr will be used after decrRef. - arr->decrRef(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); const double *coo=_coords->getConstPointer(); @@ -5270,11 +5351,10 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getWarpField() const throw(INTERP_KERN MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); ret->setMesh(this); int nbOfCells=getNumberOfCells(); - DataArrayDouble *arr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::New(); arr->alloc(nbOfCells,1); double *pt=arr->getPointer(); ret->setArray(arr);//In case of throw to avoid mem leaks arr will be used after decrRef. - arr->decrRef(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); const double *coo=_coords->getConstPointer(); @@ -5318,11 +5398,10 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getSkewField() const throw(INTERP_KERN MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); ret->setMesh(this); int nbOfCells=getNumberOfCells(); - DataArrayDouble *arr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::New(); arr->alloc(nbOfCells,1); double *pt=arr->getPointer(); ret->setArray(arr);//In case of throw to avoid mem leaks arr will be used after decrRef. - arr->decrRef(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); const double *coo=_coords->getConstPointer(); @@ -6166,14 +6245,13 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(std::vector aps(a.size()); std::copy(a.begin(),a.end(),aps.begin()); - DataArrayDouble *pts=MergeNodesArray(aps); + MEDCouplingAutoRefCountObjectPtr pts=MergeNodesArray(aps); MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New("merge",meshDim); ret->setCoords(pts); - pts->decrRef(); - DataArrayInt *c=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr c=DataArrayInt::New(); c->alloc(meshLgth,1); int *cPtr=c->getPointer(); - DataArrayInt *cI=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr cI=DataArrayInt::New(); cI->alloc(nbOfCells+1,1); int *cIPtr=cI->getPointer(); *cIPtr++=0; @@ -6202,8 +6280,6 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(std::vectorsetConnectivity(c,cI,true); - c->decrRef(); - cI->decrRef(); return ret.retn(); } @@ -6248,10 +6324,10 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vectorgetMeshLength(); meshIndexLgth+=(*iter)->getNumberOfCells(); } - DataArrayInt *nodal=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr nodal=DataArrayInt::New(); nodal->alloc(meshLgth,1); int *nodalPtr=nodal->getPointer(); - DataArrayInt *nodalIndex=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr nodalIndex=DataArrayInt::New(); nodalIndex->alloc(meshIndexLgth+1,1); int *nodalIndexPtr=nodalIndex->getPointer(); int offset=0; @@ -6273,8 +6349,6 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vectorsetMeshDimension(meshDim); ret->setConnectivity(nodal,nodalIndex,true); ret->setCoords(coords); - nodalIndex->decrRef(); - nodal->decrRef(); return ret; } @@ -6293,8 +6367,8 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vector& meshes, int compType, std::vector& corr) { //All checks are delegated to MergeUMeshesOnSameCoords - MEDCouplingUMesh *ret=MergeUMeshesOnSameCoords(meshes); - DataArrayInt *o2n=ret->zipConnectivityTraducer(compType); + MEDCouplingAutoRefCountObjectPtr ret=MergeUMeshesOnSameCoords(meshes); + MEDCouplingAutoRefCountObjectPtr o2n=ret->zipConnectivityTraducer(compType); corr.resize(meshes.size()); std::size_t nbOfMeshes=meshes.size(); int offset=0; @@ -6309,8 +6383,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::FuseUMeshesOnSameCoords(const std::vectorsetName(meshes[i]->getName()); corr[i]=tmp; } - o2n->decrRef(); - return ret; + return ret.retn(); } /*! diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index c97142d8c..5fc45aefe 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -172,6 +172,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isFullyQuadratic() const; MEDCOUPLING_EXPORT bool isPresenceOfQuadratic() const; MEDCOUPLING_EXPORT void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *convertLinearCellsToQuadratic(int conversionType=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void tessellate2D(double eps) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void tessellate2DCurve(double eps) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); @@ -270,6 +271,8 @@ namespace ParaMEDMEM static bool AreCellsEqualInPool(const std::vector& candidates, int compType, const int *conn, const int *connI, DataArrayInt *result) ; MEDCouplingUMesh *buildPartOfMySelfKeepCoords(const int *begin, const int *end) const; MEDCouplingUMesh *buildPartOfMySelfKeepCoords2(int start, int end, int step) const; + DataArrayInt *convertLinearCellsToQuadratic1D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const throw(INTERP_KERNEL::Exception); + DataArrayInt *convertLinearCellsToQuadratic2D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const throw(INTERP_KERNEL::Exception); template void getCellsContainingPointsAlg(const double *coords, const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 998a2a043..f492da9f1 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -158,6 +158,16 @@ std::set MEDCouplingUMeshDesc::getAllGeoTypes return _types; } +DataArrayInt *MEDCouplingUMeshDesc::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::giveCellsWithType : not implemented yet !"); +} + +DataArrayInt *MEDCouplingUMeshDesc::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::computeNbOfNodesPerCell : not implemented yet !"); +} + int MEDCouplingUMeshDesc::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const { const int *desc_connec=_desc_connec->getConstPointer(); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 18d3eb74a..86ef28f73 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -51,6 +51,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getMeshDimension() const { return _mesh_dim; } MEDCOUPLING_EXPORT INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const; MEDCOUPLING_EXPORT std::set getAllGeoTypes() const; + MEDCOUPLING_EXPORT DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector& conn) const; MEDCOUPLING_EXPORT std::string simpleRepr() const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index c26bbe173..b3904a716 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -274,6 +274,7 @@ void MEDCouplingBasicsTest1::testMeshPointsCloud() targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6); targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7); targetMesh->finishInsertingCells(); + CPPUNIT_ASSERT_THROW(targetMesh->checkCoherency(),INTERP_KERNEL::Exception); DataArrayDouble *myCoords=DataArrayDouble::New(); myCoords->alloc(9,3); std::copy(targetCoords,targetCoords+27,myCoords->getPointer()); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index b4446b1dd..b1a329f0a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -149,6 +149,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): targetMesh.insertNextCell(NORM_POINT1,1,[7]); targetMesh.insertNextCell(NORM_POINT1,1,[6]); targetMesh.finishInsertingCells(); + self.assertRaises(InterpKernelException,targetMesh.checkCoherency); myCoords=DataArrayDouble.New(); myCoords.setValues(targetCoords,9,3); targetMesh.setCoords(myCoords); @@ -10833,7 +10834,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass pass - def testSwigCellOrientation1(self): + def testSwig2CellOrientation1(self): coords=DataArrayDouble([-0.21606,-0.10803,0.29999999999999999,-0.21606,-0.10803,0.37700000000000006,0,-0.10803,0.29999999999999999,0,-0.10803,0.37700000000000006,0,0.10803,0.29999999999999999,0,0.10803,0.37700000000000006,-0.21606,0.10803,0.29999999999999999,-0.21606,0.10803,0.37700000000000006,0,0.03601,0.29999999999999999,0,0.03601,0.37700000000000006,0,-0.03601,0.29999999999999999,0,-0.03601,0.37700000000000006],12,3) conn=[[0,2,10,8,4,6],[1,3,11,9,5,7],[0,1,3,2],[2,3,11,10],[10,11,9,8],[8,9,5,4],[4,5,7,6],[6,7,1,0]] for i in xrange(256): @@ -10855,7 +10856,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass pass - def testSwigCheckConsecutiveCellTypesForMEDFileFrmt1(self): + def testSwig2CheckConsecutiveCellTypesForMEDFileFrmt1(self): m1=MEDCouplingUMesh("",2) ; m1.allocateCells(0) m1.insertNextCell(NORM_QUAD4,[0,1,2,3]) m1.insertNextCell(NORM_TRI3,[0,1,2]) @@ -10868,7 +10869,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(m1.checkConsecutiveCellTypesForMEDFileFrmt()) pass - def testSwigDAAccumulate1(self): + def testSwig2DAAccumulate1(self): d=DataArrayInt(10) ; d.iota(0) self.assertEqual([45],d.accumulate()) self.assertEqual(45,d.accumulate(0)) @@ -10887,7 +10888,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(155.,d.accumulate(2)) pass - def testSwigUMeshDistanceToMesh1(self): + def testSwig2UMeshDistanceToMesh1(self): m=MEDCouplingUMesh("toto",2) coords=DataArrayDouble([2.3,3.4,5.6,6.5,-4.3,3.2,-9.8,7.6,-5.4],3,3) m.setCoords(coords) @@ -10937,7 +10938,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(0.07071067811865482,a,14) ; self.assertEqual(1,b) ; self.assertEqual(2,c) pass - def testSwigNonRegressionPartitionBySpreadZone1(self): + def testSwig2NonRegressionPartitionBySpreadZone1(self): m=MEDCouplingCMesh() arr=DataArrayDouble(6) ; arr.iota(0.) m.setCoords(arr,arr,arr) @@ -11044,7 +11045,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(d2.isEqual(DataArrayInt([0,1,1,1,1,1,1,2,2,2,2,2,2,3]))) pass - def testSwigCurveLinearMesh2(self): + def testSwig2CurveLinearMesh2(self): c=MEDCouplingCMesh() #2D arr1=DataArrayDouble([0,1,3,7]) @@ -11100,7 +11101,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(cl.buildUnstructured().getBarycenterAndOwner().isEqual(DataArrayDouble(li4_1,4,2),1e-14)) pass - def testSwigCurveLinearMeshNonRegression1(self): + def testSwig2CurveLinearMeshNonRegression1(self): coords=DataArrayDouble([0.0, 0.0, 0.10000000149011612, 0.6000000238418579, 0.10000000149011612, 0.30000001192092896, 1.100000023841858, 0.10000000149011612, 0.20000000298023224, 0.10000000149011612, 0.6000000238418579, 0.20000000298023224, 0.699999988079071, 0.6000000238418579, 0.10000000149011612, 1.2000000476837158, 0.6000000238418579, 0.30000001192092896, 0.10000000149011612, 1.100000023841858, 0.30000001192092896, 0.5, 1.100000023841858, 0.20000000298023224, 1.0, 1.2000000476837158, 0.10000000149011612, 0.0, 0.10000000149011612, 0.5, 0.5, 0.10000000149011612, 0.6000000238418579, 1.2000000476837158, 0.10000000149011612, 0.699999988079071, 0.10000000149011612, 0.6000000238418579, 0.699999988079071, 0.6000000238418579, 0.6000000238418579, 0.5, 1.100000023841858, 0.6000000238418579, 0.6000000238418579, 0.10000000149011612, 1.0, 0.6000000238418579, 0.699999988079071, 1.2000000476837158, 0.699999988079071, 0.8999999761581421, 1.0, 0.5, 0.10000000149011612, 0.10000000149011612, 1.2000000476837158, 0.699999988079071, 0.10000000149011612, 1.0, 1.0, 0.10000000149011612, 1.100000023841858, 0.10000000149011612, 0.6000000238418579, 1.100000023841858, 0.6000000238418579, 0.6000000238418579, 1.100000023841858, 1.100000023841858, 0.6000000238418579, 1.2000000476837158, 0.10000000149011612, 1.2000000476837158, 1.0, 0.5, 1.100000023841858, 1.2000000476837158, 1.2000000476837158, 1.100000023841858, 1.0],27,3) m=MEDCouplingCurveLinearMesh("toto") m.setCoords(coords) @@ -11113,6 +11114,149 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(m.getBarycenterAndOwner().isEqual(m.buildUnstructured().getBarycenterAndOwner(),1e-12)) pass + def testSwig2NonRegressionDASetSelectedComponents1(self): + da=DataArrayDouble.New([1.,2.,3.,4.,5.,6.],3,2) + dv=DataArrayDouble.New(); + dv.alloc(4,4) + dv.fillWithZero() + # da has less tuples than dv + dv.setSelectedComponents(da,[1,0]) + # + self.assertTrue(dv.isEqual(DataArrayDouble([2.,1.,0.,0.,4.,3.,0.,0.,6.,5.,0.,0.,0.,0.,0.,0.],4,4),1e-14)) + # + da=DataArrayInt.New([1,2,3,4,5,6],3,2) + dv=DataArrayInt.New(); + dv.alloc(4,4) + dv.fillWithZero() + # da has less tuples than dv + dv.setSelectedComponents(da,[1,0]) + # + self.assertTrue(dv.isEqual(DataArrayInt([2,1,0,0,4,3,0,0,6,5,0,0,0,0,0,0],4,4))) + pass + + def testSwigSetItem3(self): + # 1-2 + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[3]=[1,2] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,1,2,0,0,0,0],6,2),1e-14)) + # 2-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[5,3,2]]=[1,2] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,1,2,1,2,0,0,1,2],6,2),1e-14)) + # 3-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[:]=[1,2] + self.assertTrue(d.isEqual(DataArrayDouble([1,2,1,2,1,2,1,2,1,2,1,2],6,2),1e-14)) + # 4-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([0,3,4])]=[1,2] + self.assertTrue(d.isEqual(DataArrayDouble([1,2,0,0,0,0,1,2,1,2,0,0],6,2),1e-14)) + # 5-2 + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[5,1]=[7] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,7],6,2),1e-14)) + # 6-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[3,5],1]=[7] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,7,0,0,0,7],6,2),1e-14)) + # 7-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[:-1:2,1]=[7] + self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,7,0,0,0,7,0,0],6,2),1e-14)) + # 8-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([0,3,4]),1]=[7] + self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,0,0,7,0,7,0,0],6,2),1e-14)) + # 9-2 + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[3,[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,8,7,0,0,0,0],6,2),1e-14)) + # 10-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[1,3,4],[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,8,7,0,0],6,2),1e-14)) + # 11-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1::2,[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,0,0,8,7],6,2),1e-14)) + # 12-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([1,4]),[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,0,0,8,7,0,0],6,2),1e-14)) + # 13-2 + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1,:-1]=[9] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,9,0,0,0,0,0,0,0,0,0],6,2),1e-14)) + # 14-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[1,4,5],:]=[7,8] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,7,8,0,0,0,0,7,8,7,8],6,2),1e-14)) + # 15-2 false + d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1::2,:]=[3,9] + self.assertTrue(d.isEqual(DataArrayDouble([0,0,3,9,0,0,3,9,0,0,3,9],6,2),1e-14)) + # 1-2 + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[3]=[1,2] + self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,1,2,0,0,0,0],6,2))) + # 2-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[5,3,2]]=[1,2] + self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,1,2,1,2,0,0,1,2],6,2))) + # 3-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[:]=[1,2] + self.assertTrue(d.isEqual(DataArrayInt([1,2,1,2,1,2,1,2,1,2,1,2],6,2))) + # 4-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([0,3,4])]=[1,2] + self.assertTrue(d.isEqual(DataArrayInt([1,2,0,0,0,0,1,2,1,2,0,0],6,2))) + # 5-2 + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[5,1]=[7] + self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,7],6,2))) + # 6-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[3,5],1]=[7] + self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,7,0,0,0,7],6,2))) + # 7-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[:-1:2,1]=[7] + self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,7,0,0,0,7,0,0],6,2))) + # 8-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([0,3,4]),1]=[7] + self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,0,0,7,0,7,0,0],6,2))) + # 9-2 + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[3,[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,8,7,0,0,0,0],6,2))) + # 10-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[1,3,4],[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,8,7,0,0],6,2))) + # 11-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1::2,[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,0,0,8,7],6,2))) + # 12-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[DataArrayInt([1,4]),[1,0]]=[7,8] + self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,0,0,8,7,0,0],6,2))) + # 13-2 + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1,:-1]=[9] + self.assertTrue(d.isEqual(DataArrayInt([0,0,9,0,0,0,0,0,0,0,0,0],6,2))) + # 14-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[[1,4,5],:]=[7,8] + self.assertTrue(d.isEqual(DataArrayInt([0,0,7,8,0,0,0,0,7,8,7,8],6,2))) + # 15-2 false + d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2) + d[1::2,:]=[3,9] + self.assertTrue(d.isEqual(DataArrayInt([0,0,3,9,0,0,3,9,0,0,3,9],6,2))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 8f47503cf..872da9e44 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -251,6 +251,8 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDoubleTuple::buildDADouble; %newobject ParaMEDMEM::MEDCouplingMesh::deepCpy; %newobject ParaMEDMEM::MEDCouplingMesh::checkTypeConsistencyAndContig; +%newobject ParaMEDMEM::MEDCouplingMesh::computeNbOfNodesPerCell; +%newobject ParaMEDMEM::MEDCouplingMesh::giveCellsWithType; %newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner; %newobject ParaMEDMEM::MEDCouplingMesh::getBarycenterAndOwner; %newobject ParaMEDMEM::MEDCouplingMesh::buildOrthogonalField; @@ -277,13 +279,11 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::__iter__; %newobject ParaMEDMEM::MEDCouplingUMesh::__getitem__; %newobject ParaMEDMEM::MEDCouplingUMesh::cellsByType; -%newobject ParaMEDMEM::MEDCouplingUMesh::giveCellsWithType; %newobject ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity2; %newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMesh; %newobject ParaMEDMEM::MEDCouplingUMesh::buildSpreadZonesWithPoly; -%newobject ParaMEDMEM::MEDCouplingUMesh::computeNbOfNodesPerCell; %newobject ParaMEDMEM::MEDCouplingUMesh::MergeUMeshes; %newobject ParaMEDMEM::MEDCouplingUMesh::MergeUMeshesOnSameCoords; %newobject ParaMEDMEM::MEDCouplingUMesh::ComputeSpreadZoneGradually; @@ -295,6 +295,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::computeFetchedNodeIds; %newobject ParaMEDMEM::MEDCouplingUMesh::getRenumArrForConsecutiveCellTypesSpec; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDirectionVectorField; +%newobject ParaMEDMEM::MEDCouplingUMesh::convertLinearCellsToQuadratic; %newobject ParaMEDMEM::MEDCouplingUMesh::getEdgeRatioField; %newobject ParaMEDMEM::MEDCouplingUMesh::getAspectRatioField; %newobject ParaMEDMEM::MEDCouplingUMesh::getWarpField; @@ -491,6 +492,8 @@ namespace ParaMEDMEM virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception); virtual DataArrayDouble *getCoordinatesAndOwner() const throw(INTERP_KERNEL::Exception); virtual DataArrayDouble *getBarycenterAndOwner() const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); virtual std::string simpleRepr() const; @@ -1375,7 +1378,6 @@ namespace ParaMEDMEM int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); int getMeshLength() const throw(INTERP_KERNEL::Exception); void computeTypes() throw(INTERP_KERNEL::Exception); - DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); //tools @@ -1390,7 +1392,6 @@ namespace ParaMEDMEM DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception); DataArrayInt *computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception); DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); - DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); void orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Exception); @@ -1400,6 +1401,7 @@ namespace ParaMEDMEM void tessellate2D(double eps) throw(INTERP_KERNEL::Exception); void tessellate2DCurve(double eps) throw(INTERP_KERNEL::Exception); void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); + DataArrayInt *convertLinearCellsToQuadratic(int conversionType=0) throw(INTERP_KERNEL::Exception); void convertDegeneratedCells() throw(INTERP_KERNEL::Exception); bool areOnlySimplexCells() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getEdgeRatioField() const throw(INTERP_KERNEL::Exception); @@ -3507,7 +3509,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); return self; case 3: @@ -3547,7 +3549,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); return self; case 3: @@ -3587,7 +3589,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); return self; case 3: @@ -3627,7 +3629,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); return self; case 3: @@ -3700,27 +3702,18 @@ namespace ParaMEDMEM } case 11: { - int bb=pt1.first; - int ee=pt1.second.first; - int ss=pt1.second.second; - if(ee nv(nbOfE); - for(int jj=0;jjsetPartOfValuesSimple2(i1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size()); + self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); return self; case 2: tmp=DataArrayDouble::New(); tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); return self; case 3: - self->setPartOfValues2(d1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size()); + self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); return self; default: throw INTERP_KERNEL::Exception(msg); @@ -3756,7 +3749,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); return self; case 3: @@ -3796,7 +3789,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); return self; case 3: @@ -5391,7 +5384,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); return self; case 3: @@ -5439,7 +5432,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); return self; case 3: @@ -5487,7 +5480,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); return self; case 3: @@ -5535,7 +5528,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); return self; case 3: @@ -5624,31 +5617,22 @@ namespace ParaMEDMEM } case 11: { - int bb=pt1.first; - int ee=pt1.second.first; - int ss=pt1.second.second; - if(ee nv(nbOfE); - for(int jj=0;jjsetPartOfValuesSimple2(i1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size()); + self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); return self; case 2: tmp=DataArrayInt::New(); tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size(),false); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); return self; case 3: - self->setPartOfValues2(d1,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size()); + self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); return self; case 4: tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues2(tmp,&nv[0],&nv[0]+nv.size(),&vc1[0],&vc1[0]+vc1.size()); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); return self; default: throw INTERP_KERNEL::Exception(msg); @@ -5688,7 +5672,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); return self; case 3: @@ -5736,7 +5720,7 @@ namespace ParaMEDMEM return self; case 2: tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,v1.size(),1); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); return self; case 3: @@ -6353,6 +6337,7 @@ namespace ParaMEDMEM 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); + virtual void copyTinyStringsFrom(const MEDCouplingField *other) 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); @@ -6503,8 +6488,8 @@ namespace ParaMEDMEM void setTimeUnit(const char *unit); const char *getTimeUnit() const; void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception); - void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); void copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 1998d7fdf..b22ebf533 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -40,7 +40,15 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass array.setValues(ptr,sourceMesh.getNumberOfCells(),1); srcField.setArray(array); + srcField.setName("abc") ; srcField.setDescription("def") + srcField.setTime(7.7,9,10) trgfield=remapper.transferField(srcField,4.57); + self.assertEqual("abc",trgfield.getName()) + self.assertEqual("def",trgfield.getDescription()) + a,b,c=trgfield.getTime() + self.assertAlmostEqual(7.7,a,14) + self.assertEqual(b,9) + self.assertEqual(c,10) values=trgfield.getArray().getValues(); valuesExpected=[7.5 ,7. ,7.,8.,7.5]; for i in xrange(targetMesh.getNumberOfCells()): @@ -318,6 +326,34 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(f11.getArray().isEqual(expected2,1e-13)) self.assertTrue(f22.getArray().isEqual(expected2,1e-13)) pass + + def testCellToNodeReverse3D(self): + c=DataArrayDouble([0.,1.,2.5]) + cc=MEDCouplingCMesh() + cc.setCoords(c,c,c) + um=cc.buildUnstructured() + f=um.getMeasureField(ON_CELLS) + # + n2o=um.simplexize(PLANAR_FACE_5) + f.setArray(f.getArray()[n2o]) + f.checkCoherency() + f.setNature(ConservativeVolumic) + f.setTime(5.6,7,8) + f.setName("toto") ; f.setDescription("aDescription") + p=MEDCouplingRemapper() + p.setP1P0BaryMethod(True) + p.prepare(um,um,"P1P0") + fNode=p.reverseTransferField(f,1e300) + self.assertEqual("toto",fNode.getName()) + self.assertEqual("aDescription",fNode.getDescription()) + a,b,c=fNode.getTime() + self.assertAlmostEqual(5.6,a,14) + self.assertEqual(7,b) ; self.assertEqual(8,c) + # + integExpected=34.328125 + self.assertAlmostEqual(fNode.integral(False)[0],integExpected,14) + self.assertAlmostEqual(f.integral(False)[0],integExpected,14) + pass def build2DSourceMesh_1(self): sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7] diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index 0a812c71a..aeca829c2 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -41,6 +41,7 @@ SET(medloader_SOURCES MEDFileBasis.cxx MEDFileMeshLL.cxx MEDFileField.cxx + MEDFileParameter.cxx MEDFileData.cxx SauvMedConvertor.cxx SauvReader.cxx diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index fbabd4709..e5493423a 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -40,8 +40,11 @@ MEDFileData *MEDFileData::deepCpy() const throw(INTERP_KERNEL::Exception) MEDCouplingAutoRefCountObjectPtr meshes; if((const MEDFileMeshes *)_meshes) meshes=_meshes->deepCpy(); + MEDCouplingAutoRefCountObjectPtr params; + if((const MEDFileParameters *)_params) + params=_params->deepCpy(); MEDCouplingAutoRefCountObjectPtr ret=MEDFileData::New(); - ret->_fields=fields; ret->_meshes=meshes; + ret->_fields=fields; ret->_meshes=meshes; ret->_params=params; return ret.retn(); } @@ -52,6 +55,8 @@ std::size_t MEDFileData::getHeapMemorySize() const ret+=_fields->getHeapMemorySize(); if((const MEDFileMeshes *)_meshes) ret+=_meshes->getHeapMemorySize(); + if((const MEDFileParameters *)_params) + ret+=_params->getHeapMemorySize(); return ret; } @@ -65,22 +70,32 @@ MEDFileMeshes *MEDFileData::getMeshes() const return const_cast(static_cast(_meshes)); } +MEDFileParameters *MEDFileData::getParams() const +{ + return const_cast(static_cast(_params)); +} + void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception) { - if(!fields) - throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !"); - fields->incrRef(); + if(fields) + fields->incrRef(); _fields=fields; } void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception) { - if(!meshes) - throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !"); - meshes->incrRef(); + if(meshes) + meshes->incrRef(); _meshes=meshes; } +void MEDFileData::setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception) +{ + if(params) + params->incrRef(); + _params=params; +} + int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception) { const MEDFileFields *f=_fields; @@ -97,6 +112,14 @@ int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception) return m->getNumberOfMeshes(); } +int MEDFileData::getNumberOfParams() const throw(INTERP_KERNEL::Exception) +{ + const MEDFileParameters *p=_params; + if(!p) + throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !"); + return p->getNumberOfParams(); +} + std::string MEDFileData::simpleRepr() const { std::ostringstream oss; @@ -116,7 +139,15 @@ std::string MEDFileData::simpleRepr() const tmp2->simpleReprWithoutHeader(oss); } else - oss << "No meshes set !!!\n"; + oss << "No meshes set !!!\n\n"; + oss << "Params part :\n*************\n\n"; + const MEDFileParameters *tmp3=_params; + if(tmp3) + { + tmp3->simpleReprWithoutHeader(oss); + } + else + oss << "params set !!!\n"; return oss.str(); } @@ -191,6 +222,7 @@ try { _fields=MEDFileFields::New(fileName); _meshes=MEDFileMeshes::New(fileName); + _params=MEDFileParameters::New(fileName); } catch(INTERP_KERNEL::Exception& e) { @@ -207,4 +239,7 @@ void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNE const MEDFileFields *fs=_fields; if(fs) fs->writeLL(fid); + const MEDFileParameters *ps=_params; + if(ps) + ps->writeLL(fid); } diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index c732aad9d..43d9ac219 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -22,6 +22,7 @@ #define __MEDFILEDATA_HXX__ #include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDFileParameter.hxx" #include "MEDFileField.hxx" #include "MEDFileMesh.hxx" @@ -39,10 +40,13 @@ namespace ParaMEDMEM std::size_t getHeapMemorySize() const; MEDFileFields *getFields() const; MEDFileMeshes *getMeshes() const; + MEDFileParameters *getParams() const; void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + void setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; // bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); @@ -56,6 +60,7 @@ namespace ParaMEDMEM private: MEDCouplingAutoRefCountObjectPtr _fields; MEDCouplingAutoRefCountObjectPtr _meshes; + MEDCouplingAutoRefCountObjectPtr _params; }; } diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index a94f55473..e0bb931f4 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -2219,7 +2219,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileField int nnodes=mesh2->getNumberOfNodes(); if(nnodes==da->getNbOfElems()) { - MEDCouplingAutoRefCountObjectPtr da3=da->transformWithIndArrR(arr2->getConstPointer(),arr2->getConstPointer()+arr2->getNbOfElems()); + MEDCouplingAutoRefCountObjectPtr da3=da->transformWithIndArrR(arr2->begin(),arr2->end()); ret->getArray()->renumberInPlace(da3->getConstPointer()); mesh2->setName(mesh->getName()); ret->setMesh(mesh2); @@ -5011,6 +5011,9 @@ MEDFileFieldMultiTS *MEDFileFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::E return ret.retn(); } +/*! + * \return a new allocated object that the caller should deal with. + */ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception) { const MEDFileField1TSWithoutSDA *item=_content->getTimeStepAtPos2(pos); @@ -5019,12 +5022,18 @@ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTE return ret.retn(); } +/*! + * \return a new allocated object that the caller should deal with. + */ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception) { int pos=getPosOfTimeStep(iteration,order); return getTimeStepAtPos(pos); } +/*! + * \return a new allocated object that the caller should deal with. + */ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception) { int pos=getPosGivenTime(time,eps); diff --git a/src/MEDLoader/MEDFileParameter.cxx b/src/MEDLoader/MEDFileParameter.cxx new file mode 100644 index 000000000..e9c3c9abf --- /dev/null +++ b/src/MEDLoader/MEDFileParameter.cxx @@ -0,0 +1,898 @@ +// Copyright (C) 2007-2012 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 +// +// Author : Anthony Geay (CEA/DEN) + +#include "MEDFileParameter.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include "InterpKernelAutoPtr.hxx" + +using namespace ParaMEDMEM; + +MEDFileParameter1TS::MEDFileParameter1TS(int iteration, int order, double time):_iteration(iteration),_order(order),_time(time) +{ +} + +MEDFileParameter1TS::MEDFileParameter1TS():_iteration(-1),_order(-1),_time(0.) +{ +} + +bool MEDFileParameter1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + std::ostringstream oss; + if(!other) + { what="Other is null"; return false; } + if(_iteration!=other->_iteration) + { oss << "iteration number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; } + if(_order!=other->_order) + { oss << "order number mismatches " << _iteration << " != " << other->_iteration; what=oss.str(); return false; } + if(fabs(_time-other->_time)>eps) + { oss << "time mismatches " << _time << " != " << other->_time << " eps=" << eps; what=oss.str(); return false; } + return true; +} + +MEDFileParameter1TS *MEDFileParameterDouble1TSWTI::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TSWTI(*this); +} + +bool MEDFileParameterDouble1TSWTI::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + if(!MEDFileParameter1TS::isEqual(other,eps,what)) + return false; + const MEDFileParameterDouble1TSWTI *otherC=dynamic_cast(other); + if(!otherC) + { what="IsEqual fails because this is double parameter other no !"; return false; } + if(fabs(_arr-otherC->_arr)>eps) + { std::ostringstream oss; oss << "value differ " << _arr << " != " << otherC->_arr << " (eps=" << eps << ")"; return false; } + return true; +} + +std::size_t MEDFileParameterDouble1TSWTI::getHeapMemorySize() const +{ + return sizeof(MEDFileParameterDouble1TSWTI); +} + +std::string MEDFileParameterDouble1TSWTI::simpleRepr() const +{ + std::ostringstream oss; + simpleRepr2(0,oss); + return oss.str(); +} + +void MEDFileParameterDouble1TSWTI::simpleRepr2(int bkOffset, std::ostream& oss) const +{ + std::string startOfLine(bkOffset,' '); + oss << startOfLine << "ParameterDoubleItem with (iteration,order) = (" << _iteration << "," << _order << ")" << std::endl; + oss << startOfLine << "Time associacited = " << _time << std::endl; + oss << startOfLine << "The value is ***** " << _arr << " *****" << std::endl; +} + +MEDFileParameterDouble1TSWTI *MEDFileParameterDouble1TSWTI::New(int iteration, int order, double time) +{ + return new MEDFileParameterDouble1TSWTI(iteration,order,time); +} + +MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI():_arr(std::numeric_limits::max()) +{ +} + +MEDFileParameterDouble1TSWTI::MEDFileParameterDouble1TSWTI(int iteration, int order, double time):MEDFileParameter1TS(iteration,order,time) +{ +} + +void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; oss << "MEDFileParameterDouble1TS::finishLoading : no specified time step (" << dt << "," << it << ") ! Time steps available : "; + for(int i=0;i(&_arr)); + return ; + } + else + { + oss << "(" << locDt << "," << locIt << ")"; + if(i!=nbOfSteps-1) + oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +void MEDFileParameterDouble1TSWTI::readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) +{ + MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast(&_arr)); +} + +void MEDFileParameterDouble1TSWTI::finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception) +{ + int locDt,locIt; + double dt; + MEDparameterComputationStepInfo(fid,name.c_str(),timeStepId+1,&locDt,&locIt,&dt); + _iteration=locDt; _order=locIt; _time=dt; + MEDparameterValueRd(fid,name.c_str(),_iteration,_order,reinterpret_cast(&_arr)); +} + +void MEDFileParameterDouble1TSWTI::writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) +{ + char nameW[MED_NAME_SIZE+1]; + MEDLoaderBase::safeStrCpy(name.c_str(),MED_NAME_SIZE,nameW,mw.getTooLongStrPolicy()); + MEDparameterValueWr(fid,nameW,_iteration,_order,_time,reinterpret_cast(&_arr)); +} + +std::size_t MEDFileParameterTinyInfo::getHeapMemSizeOfStrings() const +{ + return _dt_unit.capacity()+_name.capacity()+_desc_name.capacity(); +} + +bool MEDFileParameterTinyInfo::isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const +{ + std::ostringstream oss; + if(_name!=other._name) + { oss << "name differ ! this=" << _name << " and other=" << other._name; what=oss.str(); return false; } + if(_desc_name!=other._desc_name) + { oss << "name differ ! this=" << _desc_name << " and other=" << other._desc_name; what=oss.str(); return false; } + if(_dt_unit!=other._dt_unit) + { oss << "unit of time differ ! this=" << _dt_unit << " and other=" << other._dt_unit; what=oss.str(); return false; } + return true; +} + +void MEDFileParameterTinyInfo::writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception) +{ + char nameW[MED_NAME_SIZE+1],descW[MED_COMMENT_SIZE+1],dtunitW[MED_SNAME_SIZE+1]; + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,nameW,getTooLongStrPolicy()); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,descW,getTooLongStrPolicy()); + MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_SNAME_SIZE,dtunitW,getTooLongStrPolicy()); + MEDparameterCr(fid,nameW,typ,descW,dtunitW); +} + +void MEDFileParameterTinyInfo::mainRepr(int bkOffset, std::ostream& oss) const +{ + std::string startOfLine(bkOffset,' '); + oss << startOfLine << "Parameter with name \"" << _name << "\"" << std::endl; + oss << startOfLine << "Parameter with description \"" << _desc_name << "\"" << std::endl; + oss << startOfLine << "Parameter with unit name \"" << _dt_unit << "\"" << std::endl; +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New() +{ + return new MEDFileParameterDouble1TS; +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName); +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName,paramName); +} + +MEDFileParameterDouble1TS *MEDFileParameterDouble1TS::New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(fileName,paramName,dt,it); +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS() +{ +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : "; + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,_name,0); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + oss << paramNameCpp; + if(i!=nbPar-1) oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +MEDFileParameterDouble1TS::MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + if(nbPar<1) + { + std::ostringstream oss2; oss2 << "No parameter in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + int nbOfSteps; + MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps); + std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE); + if(paramType==MED_FLOAT64) + { + if(nbOfSteps>0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,_name,0); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Double param name \"" << paramNameCpp << "\" exists in file \""<< fileName << "\"but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + std::ostringstream oss2; oss2 << "First parameter in file \"" << fileName << "\" is not double !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } +} + +bool MEDFileParameterDouble1TS::isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const +{ + if(!MEDFileParameterDouble1TSWTI::isEqual(other,eps,what)) + return false; + const MEDFileParameterDouble1TS *otherC=dynamic_cast(other); + if(!otherC) + { what="Other is not of type MEDFileParameterDouble1TS as this"; return false; } + if(!isEqualStrings(*otherC,what)) + return false; + return true; +} + +MEDFileParameter1TS *MEDFileParameterDouble1TS::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterDouble1TS(*this); +} + +std::string MEDFileParameterDouble1TS::simpleRepr() const +{ + std::ostringstream oss; + MEDFileParameterTinyInfo::mainRepr(0,oss); + MEDFileParameterDouble1TSWTI::simpleRepr2(0,oss); + return oss.str(); +} + +std::size_t MEDFileParameterDouble1TS::getHeapMemorySize() const +{ + return getHeapMemSizeOfStrings()+sizeof(MEDFileParameterDouble1TS); +} + +void MEDFileParameterDouble1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + MEDFileParameterTinyInfo::writeLLHeader(fid,MED_FLOAT64); + MEDFileParameterDouble1TSWTI::writeLL(fid,_name,*this); +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New() +{ + return new MEDFileParameterMultiTS; +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(fileName); +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(fileName,paramName); +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS() +{ +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy):MEDFileParameterTinyInfo(other),_param_per_ts(other._param_per_ts) +{ + if(deepCopy) + for(std::size_t i=0;i<_param_per_ts.size();i++) + { + const MEDFileParameter1TS *elt=_param_per_ts[i]; + if(elt) + _param_per_ts[i]=elt->deepCpy(); + } +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + if(nbPar<1) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS : no parameter in file \"" << fileName << "\" !" ; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + int nbOfSteps; + MEDparameterInfo(fid,1,pName,¶mType,descName,unitName,&nbOfSteps); + std::string paramNameCpp=MEDLoaderBase::buildStringFromFortran(pName,MED_NAME_SIZE); + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,paramType,nbOfSteps); +} + +MEDFileParameterMultiTS::MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + std::ostringstream oss; oss << "MEDFileParameterDouble1TS : no double param name \"" << paramName << "\" ! Double Parameters available are : "; + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i0) + { + _dt_unit=MEDLoaderBase::buildStringFromFortran(unitName,MED_SNAME_SIZE); + _name=paramNameCpp; + _desc_name=MEDLoaderBase::buildStringFromFortran(descName,MED_COMMENT_SIZE); + finishLoading(fid,paramType,nbOfSteps); + return ; + } + else + { + std::ostringstream oss2; oss2 << "Param name \"" << paramName << "\" exists but no time steps on it !"; + throw INTERP_KERNEL::Exception(oss2.str().c_str()); + } + } + else + { + oss << paramNameCpp; + if(i!=nbPar-1) oss << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +void MEDFileParameterMultiTS::finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception) +{ + _param_per_ts.resize(nbOfSteps); + for(int i=0;ireadValue(fid,_name.c_str()); + break; + /*case MED_INT32; + _param_per_ts[i]=; + break;*/ + default: + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::finishLoading : supporting only FLOAT64 !"); + } + } +} + +std::size_t MEDFileParameterMultiTS::getHeapMemorySize() const +{ + std::size_t ret=sizeof(MEDFileParameterMultiTS); + std::size_t ret2=sizeof(MEDCouplingAutoRefCountObjectPtr)*_param_per_ts.capacity(); + for(std::size_t i=0;i<_param_per_ts.size();i++) + { + const MEDFileParameter1TS *pt(_param_per_ts[i]); + if(pt) + ret2+=pt->getHeapMemorySize(); + } + return ret2+ret; +} + +MEDFileParameterMultiTS *MEDFileParameterMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameterMultiTS(*this,true); +} + +bool MEDFileParameterMultiTS::isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const +{ + if(!other) + { what="other is null !"; return false; } + if(_param_per_ts.size()!=other->_param_per_ts.size()) + { what="number of time steps differs !"; return false; } + std::ostringstream oss; + for(std::size_t i=0;i<_param_per_ts.size();i++) + { + const MEDFileParameter1TS *a(_param_per_ts[i]),*b(other->_param_per_ts[i]); + if((a && !b) || (!a && b)) + { oss << "At time step id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; } + if(a) + if(!a->isEqual(b,eps,what)) + { oss << " At time step id #" << i << " non equality !"; what+=oss.str(); return false; } + } + return true; +} + +void MEDFileParameterMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeLL(fid,*this); +} + +void MEDFileParameterMultiTS::writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) +{ + std::set diffType; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(dynamic_cast(elt)) + diffType.insert(MED_FLOAT64); + } + if(diffType.size()>1) + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::writeLL : impossible to mix type of data in parameters in MED file ! Only float64 or only int32 ..."); + if(diffType.empty()) + return; + med_parameter_type typ=*diffType.begin(); + MEDFileParameterTinyInfo::writeLLHeader(fid,typ); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + elt->writeLL(fid,_name,mw); + } +} + +std::string MEDFileParameterMultiTS::simpleRepr() const +{ + std::ostringstream oss; + simpleRepr2(0,oss); + return oss.str(); +} + +void MEDFileParameterMultiTS::simpleRepr2(int bkOffset, std::ostream& oss) const +{ + MEDFileParameterTinyInfo::mainRepr(bkOffset,oss); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + elt->simpleRepr2(bkOffset+2,oss); + } +} + +void MEDFileParameterMultiTS::appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr elt=MEDFileParameterDouble1TSWTI::New(dt,it,time); + elt->setValue(val); + MEDCouplingAutoRefCountObjectPtr elt2((MEDFileParameterDouble1TSWTI*)elt); elt2->incrRef(); + _param_per_ts.push_back(elt2); +} + +double MEDFileParameterMultiTS::getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosOfTimeStep(iteration,order); + const MEDFileParameter1TS *elt=_param_per_ts[pos]; + if(!elt) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order; + oss << " exists but elt is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileParameterDouble1TSWTI *eltC=dynamic_cast(elt); + if(!eltC) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getDoubleValue : time iteration it=" << iteration << " order=" << order; + oss << " exists but not double !"; + } + return eltC->getValue(); +} + +int MEDFileParameterMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosOfTimeStep : no such iteration=" << iteration << " order=" << order << " ! Possibilities are :"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + if(elt->getIteration()==iteration && elt->getOrder()) + return ret; + else + oss << "(" << elt->getIteration() << "," << elt->getOrder() << "), "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileParameterMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getPosGivenTime : no such time=" << time << " ! Possibilities are :"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++,ret++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + if(fabs(elt->getTimeValue()-time)<=eps) + return ret; + else + oss << elt->getTimeValue() << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +/*! + * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer. + */ +MEDFileParameter1TS *MEDFileParameterMultiTS::getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception) +{ + if(posId<0 || posId>=(int)_param_per_ts.size()) + { + std::ostringstream oss; oss << "MEDFileParameterMultiTS::getTimeStepAtPos : invalid pos ! Should be in [0," << _param_per_ts.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return const_cast(static_cast(_param_per_ts[posId])); +} + +void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception) +{ + std::vector b(_param_per_ts.size(),true); + int len=(int)_param_per_ts.size(); + for(const int *w=startIds;w!=endIds;w++) + if(*w>=0 && *w > paramPerTs(newNb); + std::size_t j=0; + for(std::size_t i=0;i<_param_per_ts.size();i++) + if(b[i]) + paramPerTs[j++]=_param_per_ts[i]; + _param_per_ts=paramPerTs; +} + +std::vector< std::pair > MEDFileParameterMultiTS::getIterations() const throw(INTERP_KERNEL::Exception) +{ + std::vector< std::pair > ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + ret.push_back(std::pair(elt->getIteration(),elt->getOrder())); + } + return ret; +} + +/*! + * \param [out] ret1 + */ +std::vector< std::pair > MEDFileParameterMultiTS::getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception) +{ + std::vector< std::pair > ret0; + ret1.clear(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_param_per_ts.begin();it!=_param_per_ts.end();it++) + { + const MEDFileParameter1TS *elt(*it); + if(elt) + { + ret0.push_back(std::pair(elt->getIteration(),elt->getOrder())); + ret1.push_back(elt->getTimeValue()); + } + } + return ret0; +} + +MEDFileParameters *MEDFileParameters::New() +{ + return new MEDFileParameters; +} + +MEDFileParameters *MEDFileParameters::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameters(fileName); +} + +MEDFileParameters::MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int nbPar=MEDnParameter(fid); + _params.resize(nbPar); + INTERP_KERNEL::AutoPtr pName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr descName=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr unitName=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE); + med_parameter_type paramType; + for(int i=0;i)*_params.capacity(); + for(std::size_t i=0;i<_params.size();i++) + { + const MEDFileParameterMultiTS *pt(_params[i]); + if(pt) + ret2+=pt->getHeapMemorySize(); + } + return ret2+ret; +} + +MEDFileParameters *MEDFileParameters::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + return new MEDFileParameters(*this,true); +} + +bool MEDFileParameters::isEqual(const MEDFileParameters *other, double eps, std::string& what) const +{ + if(!other) + { what="other is null !"; return false; } + if(_params.size()!=other->_params.size()) + { what="number of parameters differs !"; return false; } + std::ostringstream oss; + for(std::size_t i=0;i<_params.size();i++) + { + const MEDFileParameterMultiTS *a(_params[i]),*b(other->_params[i]); + if((a && !b) || (!a && b)) + { oss << "At param with id #" << i << " pointer is defined on one side not in the other !"; what=oss.str(); return false; } + if(a) + if(!a->isEqual(b,eps,what)) + { oss << " At param with id #" << i << " non equality !"; what+=oss.str(); return false; } + } + return true; +} + +MEDFileParameters::MEDFileParameters(const MEDFileParameters& other, bool deepCopy):MEDFileWritable(other),_params(other._params) +{ + if(deepCopy) + for(std::size_t i=0;i<_params.size();i++) + { + const MEDFileParameterMultiTS *elt=_params[i]; + if(elt) + _params[i]=elt->deepCpy(); + } +} + +void MEDFileParameters::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeLL(fid); +} + +void MEDFileParameters::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + elt->writeLL(fid,*this); + } +} + +std::vector MEDFileParameters::getParamsNames() const throw(INTERP_KERNEL::Exception) +{ + std::vector ret(_params.size()); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++,i++) + { + const MEDFileParameterMultiTS *p=(*it); + if(p) + { + ret[i]=p->getName(); + } + else + { + std::ostringstream oss; oss << "MEDFileParameters::getParamsNames : At rank #" << i << " param is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + +std::string MEDFileParameters::simpleRepr() const +{ + std::ostringstream oss; + simpleReprWithoutHeader(oss); + return oss.str(); +} + +void MEDFileParameters::simpleReprWithoutHeader(std::ostream& oss) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + elt->simpleRepr2(2,oss); + } +} + +void MEDFileParameters::resize(int newSize) throw(INTERP_KERNEL::Exception) +{ + if(newSize<0) + throw INTERP_KERNEL::Exception("MEDFileParameters::resize : should be positive !"); + _params.resize(newSize); +} + +void MEDFileParameters::pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception) +{ + if(param) + param->incrRef(); + MEDCouplingAutoRefCountObjectPtr elt(param); + _params.push_back(elt); +} + +void MEDFileParameters::setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception) +{ + if(i<0) + throw INTERP_KERNEL::Exception("MEDFileParameters::setParamAtPos : should be positive !"); + if(i>=(int)_params.size()) + _params.resize(i+1); + if(param) + param->incrRef(); + MEDCouplingAutoRefCountObjectPtr elt(param); + _params[i]=elt; +} + +/*! + * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer. + */ +MEDFileParameterMultiTS *MEDFileParameters::getParamAtPos(int i) const throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_params.size()) + { + std::ostringstream oss; oss << "MEDFileParameters::getParamAtPos : should be in [0," << _params.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileParameterMultiTS *elt=_params[i]; + return const_cast(elt); +} + +/*! + * \return an internal pointer that can be null. Warning the caller is \b not responsible of the returned pointer. + */ +MEDFileParameterMultiTS *MEDFileParameters::getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosFromParamName(paramName); + return getParamAtPos(pos); +} + +void MEDFileParameters::destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_params.size()) + { + std::ostringstream oss; oss << "MEDFileParameters::destroyParamAtPos : should be in [0," << _params.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _params[i]=MEDCouplingAutoRefCountObjectPtr(0); +} + +int MEDFileParameters::getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; oss << "MEDFileParameters::getPosFromParamName : no such name=" << paramName << " ! Possibilities are :"; + int ret=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_params.begin();it!=_params.end();it++,ret++) + { + const MEDFileParameterMultiTS *elt(*it); + if(elt) + { + if(std::string(elt->getName())==paramName) + return ret; + else + oss << elt->getName() << ", "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileParameters::getNumberOfParams() const throw(INTERP_KERNEL::Exception) +{ + return (int)_params.size(); +} diff --git a/src/MEDLoader/MEDFileParameter.hxx b/src/MEDLoader/MEDFileParameter.hxx new file mode 100644 index 000000000..c3e61962c --- /dev/null +++ b/src/MEDLoader/MEDFileParameter.hxx @@ -0,0 +1,182 @@ +// Copyright (C) 2007-2012 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 +// +// Author : Anthony Geay (CEA/DEN) + +#ifndef __MEDFILEPARAMETER_HXX__ +#define __MEDFILEPARAMETER_HXX__ + +#include "MEDLoaderDefines.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +namespace ParaMEDMEM +{ + class MEDLOADER_EXPORT MEDFileParameter1TS : public RefCountObject + { + public: + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception) = 0; + virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + virtual void simpleRepr2(int bkOffset, std::ostream& oss) const = 0; + virtual void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) = 0; + virtual void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) = 0; + public: + void setIteration(int it) { _iteration=it; } + int getIteration() const { return _iteration; } + void setOrder(int order) { _order=order; } + int getOrder() const { return _order; } + void setTimeValue(double time) { _time=time; } + void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; } + double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; } + double getTimeValue() const { return _time; } + protected: + MEDFileParameter1TS(int iteration, int order, double time); + MEDFileParameter1TS(); + protected: + int _iteration; + int _order; + double _time; + }; + + class MEDLOADER_EXPORT MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS + { + public: + static MEDFileParameterDouble1TSWTI *New(int iteration, int order, double time); + MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + void setValue(double val) throw(INTERP_KERNEL::Exception) { _arr=val; } + double getValue() const throw(INTERP_KERNEL::Exception) { return _arr; } + bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + std::size_t getHeapMemorySize() const; + void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + protected: + MEDFileParameterDouble1TSWTI(); + MEDFileParameterDouble1TSWTI(int iteration, int order, double time); + void simpleRepr2(int bkOffset, std::ostream& oss) const; + void finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception); + protected: + double _arr; + }; + + class MEDLOADER_EXPORT MEDFileParameterTinyInfo : public MEDFileWritable + { + public: + void setDescription(const char *name) { _desc_name=name; } + const char *getDescription() const { return _desc_name.c_str(); } + void setTimeUnit(const char *unit) { _dt_unit=unit; } + const char *getTimeUnit() const { return _dt_unit.c_str(); } + std::size_t getHeapMemSizeOfStrings() const; + bool isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const; + protected: + void writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception); + void mainRepr(int bkOffset, std::ostream& oss) const; + protected: + std::string _dt_unit; + std::string _name; + std::string _desc_name; + }; + + class MEDLOADER_EXPORT MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterDouble1TS *New(); + static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const; + virtual std::string simpleRepr() const; + std::size_t getHeapMemorySize() const; + void setName(const char *name) throw(INTERP_KERNEL::Exception) { _name=name; } + const char *getName() const throw(INTERP_KERNEL::Exception) { return _name.c_str(); } + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + private: + MEDFileParameterDouble1TS(); + MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + }; + + class MEDLOADER_EXPORT MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterMultiTS *New(); + static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + const char *getName() const { return _name.c_str(); } + void setName(const char *name) { _name=name; } + std::size_t getHeapMemorySize() const; + MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const; + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception); + double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + MEDFileParameter1TS *getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception); + void eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception); + std::vector< std::pair > getIterations() const throw(INTERP_KERNEL::Exception); + std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); + void simpleRepr2(int bkOffset, std::ostream& oss) const; + protected: + MEDFileParameterMultiTS(); + MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy); + MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception); + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _param_per_ts; + }; + + class MEDLOADER_EXPORT MEDFileParameters : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileParameters *New(); + static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySize() const; + MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileParameters *other, double eps, std::string& what) const; + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + std::vector getParamsNames() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void simpleReprWithoutHeader(std::ostream& oss) const; + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception); + MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception); + void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception); + int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); + protected: + void simpleRepr2(int bkOffset, std::ostream& oss) const; + MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameters(const MEDFileParameters& other, bool deepCopy); + MEDFileParameters(); + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _params; + }; +} + +#endif diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index ccb326f69..cd3ae6450 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -37,15 +37,16 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ -MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx MEDFileData.hxx \ +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ +MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx MEDFileData.hxx MEDFileParameter.hxx \ SauvMedConvertor.hxx SauvReader.hxx SauvWriter.hxx SauvUtilities.hxx dist_libmedloader_la_SOURCES= \ MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ -MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx \ -SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx +MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx \ +SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx \ +MEDFileParameter.cxx libmedloader_la_CPPFLAGS= $(MED3_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index bf2c9d1d0..7c775dbef 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -268,7 +268,7 @@ const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::Normali { static vector conn; static const int hexa20 [] = {0,6,4,2, 12,18,16,14, 7,5,3,1, 19,17,15,13, 8,11,10,9}; - static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,7,3}; + static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,8,7}; static const int pyra13 [] = {0,2,4,6, 12, 1,3,5,7, 8,9,10,11}; static const int tetra10[] = {0,2,4, 9, 1,3,5, 6,7,8}; static const int quad8 [] = {0,2,4,6, 1,3,5,7}; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 84736406e..6082423e5 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -29,6 +29,7 @@ #include "MEDLoader.hxx" #include "MEDFileMesh.hxx" #include "MEDFileField.hxx" +#include "MEDFileParameter.hxx" #include "MEDFileData.hxx" #include "MEDLoaderTypemaps.i" #include "SauvReader.hxx" @@ -46,6 +47,11 @@ using namespace ParaMEDMEM; $result=convertMEDFileMesh($1,$owner); } +%typemap(out) ParaMEDMEM::MEDFileParameter1TS* +{ + $result=convertMEDFileParameter1TS($1,$owner); +} + %newobject MEDLoader::ReadUMeshFromFamilies; %newobject MEDLoader::ReadUMeshFromGroups; %newobject MEDLoader::ReadUMeshFromFile; @@ -121,6 +127,19 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileData::deepCpy; %newobject ParaMEDMEM::MEDFileData::getMeshes; %newobject ParaMEDMEM::MEDFileData::getFields; +%newobject ParaMEDMEM::MEDFileData::getParams; + +%newobject ParaMEDMEM::MEDFileParameterDouble1TS::New; +%newobject ParaMEDMEM::MEDFileParameterDouble1TS::deepCpy; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::New; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::deepCpy; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::getTimeStepAtPos; +%newobject ParaMEDMEM::MEDFileParameterMultiTS::__getitem__; +%newobject ParaMEDMEM::MEDFileParameters::New; +%newobject ParaMEDMEM::MEDFileParameters::deepCpy; +%newobject ParaMEDMEM::MEDFileParameters::getParamAtPos; +%newobject ParaMEDMEM::MEDFileParameters::getParamWithName; +%newobject ParaMEDMEM::MEDFileParameters::__getitem__; %newobject ParaMEDMEM::SauvWriter::New; %newobject ParaMEDMEM::SauvReader::New; @@ -135,6 +154,11 @@ using namespace ParaMEDMEM; %feature("unref") MEDFileField1TS "$this->decrRef();" %feature("unref") MEDFileFieldMultiTS "$this->decrRef();" %feature("unref") MEDFileFields "$this->decrRef();" +%feature("unref") MEDFileParameter1TS "$this->decrRef();" +%feature("unref") MEDFileParameterDouble1TSWTI "$this->decrRef();" +%feature("unref") MEDFileParameterDouble1TS "$this->decrRef();" +%feature("unref") MEDFileParameterMultiTS "$this->decrRef();" +%feature("unref") MEDFileParameters "$this->decrRef();" %feature("unref") MEDFileData "$this->decrRef();" %feature("unref") SauvReader "$this->decrRef();" %feature("unref") SauvWriter "$this->decrRef();" @@ -338,7 +362,7 @@ namespace ParaMEDMEM { public: static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); - static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1); + static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); virtual MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); virtual MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); virtual void clearNonDiscrAttributes() const; @@ -358,8 +382,8 @@ namespace ParaMEDMEM void setTimeUnit(const char *unit); const char *getTimeUnit() const; virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception); - std::vector getNonEmptyLevels() const; - std::vector getNonEmptyLevelsExt() const; + std::vector getNonEmptyLevels() const throw(INTERP_KERNEL::Exception); + std::vector getNonEmptyLevelsExt() const throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); // @@ -428,7 +452,7 @@ namespace ParaMEDMEM return MEDFileMesh::New(fileName); } - MEDFileMesh(const char *fileName, const char *mName, int dt=-1, int it=-1) + MEDFileMesh(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception) { return MEDFileMesh::New(fileName,mName,dt,it); } @@ -1674,6 +1698,371 @@ namespace ParaMEDMEM } }; + class MEDFileParameter1TS : public RefCountObject + { + public: + void setIteration(int it); + int getIteration() const; + void setOrder(int order); + int getOrder() const; + void setTimeValue(double time); + void setTime(int dt, int it, double time); + double getTime(int& dt, int& it); + double getTimeValue() const; + }; + + class MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS + { + public: + void setValue(double val) throw(INTERP_KERNEL::Exception); + double getValue() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + } + }; + + class MEDFileParameterTinyInfo : public MEDFileWritable + { + public: + void setDescription(const char *name); + const char *getDescription() const; + void setTimeUnit(const char *unit); + const char *getTimeUnit() const; + }; + + class MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterDouble1TS *New(); + static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception); + virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual std::string simpleRepr() const; + void setName(const char *name) throw(INTERP_KERNEL::Exception); + const char *getName() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameterDouble1TS() + { + return MEDFileParameterDouble1TS::New(); + } + + MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName); + } + + MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName,paramName); + } + + MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception) + { + return MEDFileParameterDouble1TS::New(fileName,paramName,dt,it); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileParameter1TS *other, double eps) const + { + std::string what; + bool ret0=self->isEqual(other,eps,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + } + }; + + class MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo + { + public: + static MEDFileParameterMultiTS *New(); + static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception); + const char *getName() const; + void setName(const char *name); + MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception); + double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameterMultiTS() + { + return MEDFileParameterMultiTS::New(); + } + + MEDFileParameterMultiTS(const char *fileName) + { + return MEDFileParameterMultiTS::New(fileName); + } + + MEDFileParameterMultiTS(const char *fileName, const char *paramName) + { + return MEDFileParameterMultiTS::New(fileName,paramName); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileParameterMultiTS *other, double eps) const + { + std::string what; + bool ret0=self->isEqual(other,eps,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + + void eraseTimeStepIds(PyObject *ids) throw(INTERP_KERNEL::Exception) + { + int sw; + int pos1; + std::vector pos2; + DataArrayInt *pos3=0; + DataArrayIntTuple *pos4=0; + convertObjToPossibleCpp1(ids,sw,pos1,pos2,pos3,pos4); + switch(sw) + { + case 1: + { + self->eraseTimeStepIds(&pos1,&pos1+1); + return; + } + case 2: + { + if(pos2.empty()) + return; + self->eraseTimeStepIds(&pos2[0],&pos2[0]+pos2.size()); + return ; + } + case 3: + { + self->eraseTimeStepIds(pos3->begin(),pos3->end()); + return ; + } + default: + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::eraseTimeStepIds : unexpected input array type recognized !"); + } + } + + int getTimeStepId(PyObject *elt0) const throw(INTERP_KERNEL::Exception) + { + if(elt0 && PyInt_Check(elt0)) + {//fmts[3] + int pos=PyInt_AS_LONG(elt0); + return pos; + } + else if(elt0 && PyTuple_Check(elt0)) + { + if(PyTuple_Size(elt0)==2) + { + PyObject *o0=PyTuple_GetItem(elt0,0); + PyObject *o1=PyTuple_GetItem(elt0,1); + if(PyInt_Check(o0) && PyInt_Check(o1)) + {//fmts(1,-1) + int iter=PyInt_AS_LONG(o0); + int order=PyInt_AS_LONG(o1); + return self->getPosOfTimeStep(iter,order); + } + else + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input param ! input is a tuple of size 2 but two integers are expected in this tuple to request a time steps !"); + } + else + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input param ! input is a tuple of size != 2 ! two integers are expected in this tuple to request a time steps !"); + } + else if(elt0 && PyFloat_Check(elt0)) + { + double val=PyFloat_AS_DOUBLE(elt0); + return self->getPosGivenTime(val); + } + else + throw INTERP_KERNEL::Exception("MEDFileParameterMultiTS::getTimeStepId : invalid input params ! expected fmts[int], fmts[int,int] or fmts[double] to request time step !"); + } + + MEDFileParameter1TS *__getitem__(PyObject *elt0) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameter1TS *ret=self->getTimeStepAtPos(ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepId(self,elt0)); + if(ret) + ret->incrRef(); + return ret; + } + + std::vector getTimeStepIds(PyObject *elts) const throw(INTERP_KERNEL::Exception) + { + if(PyList_Check(elts)) + { + int sz=PyList_Size(elts); + std::vector ret(sz); + for(int i=0;i ret(1); + ret[0]=ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepId(self,elts); + return ret; + } + } + + void __delitem__(PyObject *elts) throw(INTERP_KERNEL::Exception) + { + std::vector idsToRemove=ParaMEDMEM_MEDFileParameterMultiTS_getTimeStepIds(self,elts); + if(!idsToRemove.empty()) + self->eraseTimeStepIds(&idsToRemove[0],&idsToRemove[0]+idsToRemove.size()); + } + + MEDFileParameter1TS *getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameter1TS *ret=self->getTimeStepAtPos(posId); + if(ret) + ret->incrRef(); + return ret; + } + + PyObject *getIterations() const throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > res=self->getIterations(); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + + PyObject *getTimeSteps() const throw(INTERP_KERNEL::Exception) + { + std::vector res2; + std::vector< std::pair > res=self->getTimeSteps(res2); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(3); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second)); + PyTuple_SetItem(elt,2,SWIG_From_double(res2[rk])); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + } + }; + + class MEDFileParameters : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileParameters *New(); + static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + std::vector getParamsNames() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception); + void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception); + int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileParameters() + { + return MEDFileParameters::New(); + } + + MEDFileParameters(const char *fileName) + { + return MEDFileParameters::New(fileName); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + MEDFileParameterMultiTS *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + if(PyInt_Check(obj)) + { + MEDFileParameterMultiTS *ret=self->getParamAtPos((int)PyInt_AS_LONG(obj)); + if(ret) + ret->incrRef(); + return ret; + } + else if(PyString_Check(obj)) + { + MEDFileParameterMultiTS *ret=self->getParamWithName(PyString_AsString(obj)); + if(ret) + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception("MEDFileParameters::__getitem__ : only integer or string with meshname supported !"); + } + + MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameterMultiTS *ret=self->getParamAtPos(i); + if(ret) + ret->incrRef(); + return ret; + } + + MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception) + { + MEDFileParameterMultiTS *ret=self->getParamWithName(paramName); + if(ret) + ret->incrRef(); + return ret; + } + + PyObject *isEqual(const MEDFileParameters *other, double eps) const + { + std::string what; + bool ret0=self->isEqual(other,eps,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + } + }; + class MEDFileData : public RefCountObject, public MEDFileWritable { public: @@ -1682,8 +2071,10 @@ namespace ParaMEDMEM MEDFileData *deepCpy() const throw(INTERP_KERNEL::Exception); void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + void setParams(MEDFileParameters *params) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + int getNumberOfParams() const throw(INTERP_KERNEL::Exception); // bool changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception); bool unPolyzeMeshes() throw(INTERP_KERNEL::Exception); @@ -1714,6 +2105,14 @@ namespace ParaMEDMEM return ret; } + MEDFileParameters *getParams() const throw(INTERP_KERNEL::Exception) + { + MEDFileParameters *ret=self->getParams(); + if(ret) + ret->incrRef(); + return ret; + } + MEDFileFields *getFields() const throw(INTERP_KERNEL::Exception) { MEDFileFields *ret=self->getFields(); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 3f66653fd..cdef0aa24 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -29,6 +29,7 @@ class MEDLoaderTest(unittest.TestCase): fileName="Pyfile18.med" mname="ExampleOfMultiDimW" medmesh=MEDFileMesh.New(fileName,mname) + self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"") self.assertEqual((0,-1),medmesh.getNonEmptyLevels()) m1_0=medmesh.getLevel0Mesh(True) m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0) @@ -2004,6 +2005,59 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(m1.getMesh().isEqual(mesh,1e-12)) pass + def testParameters1(self): + fname="Pyfile56.med" + m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh") + mm=MEDFileCMesh() ; mm.setMesh(m) + ms=MEDFileMeshes() ; ms.pushMesh(mm) + data=MEDFileData() + p=MEDFileParameters() + data.setParams(p) ; data.setMeshes(ms) + pts=MEDFileParameterMultiTS() + pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms") + pts.appendValue(1,2,3.4,567.89) + pts.appendValue(2,3,5.6,999.123) + pts2=pts.deepCpy() ; pts2.setName("B") ; pts2.setDescription("A second example") + p.pushParam(pts) ; p.pushParam(pts2) + data.write(fname,2) + p2=MEDFileParameters(fname) + self.assertTrue(p.isEqual(p2,1e-14)[0]) + self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13) + p3=p.deepCpy() + pts4=pts2.deepCpy() + pts3=pts2.deepCpy() + self.assertTrue(pts3.isEqual(pts2,1e-14)[0]) + pts2.eraseTimeStepIds([0]) + self.assertTrue(not pts3.isEqual(pts2,1e-14)[0]) + del pts3[[3.4]] + self.assertTrue(pts3.isEqual(pts2,1e-14)[0]) + self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2)) + self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2)) + self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13) + self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13) + p=p3 + self.assertTrue(p.isEqual(p2,1e-14)[0]) + self.assertTrue(p2["B"].isEqual(pts,1e-14)[0]) + self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0]) + self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13) + self.assertEqual(p.getParamsNames(),('A','B')) + ptsr=MEDFileParameterMultiTS(fname,"B") + self.assertTrue(ptsr.isEqual(pts4,1e-14)[0]) + ptsr=MEDFileParameterMultiTS(fname) + self.assertTrue(ptsr.isEqual(pts,1e-14)[0]) + p1tsr=MEDFileParameterDouble1TS(fname) + self.assertEqual(p1tsr.getName(),"A") + self.assertAlmostEqual(p1tsr.getValue(),567.89,13) + p1tsr=MEDFileParameterDouble1TS(fname,"B") + self.assertEqual(p1tsr.getName(),"B") + self.assertAlmostEqual(p1tsr.getValue(),567.89,13) + p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3) + self.assertEqual(p1tsr.getName(),"B") + self.assertAlmostEqual(p1tsr.getValue(),999.123,13) + data2=MEDFileData(fname) + self.assertEqual(2,data2.getNumberOfParams()) + self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13) + pass pass unittest.main() diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index cbab3a4d0..07ae0b12e 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -34,6 +34,18 @@ static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) th return ret; } +static PyObject* convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=0; + if(dynamic_cast(p1ts)) + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner); + if(dynamic_cast(p1ts)) + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TSWTI,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !"); + return ret; +} + static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception) { std::vector > ret; diff --git a/src/MEDPartitioner/Makefile.am b/src/MEDPartitioner/Makefile.am index 3efca0b19..f49477518 100644 --- a/src/MEDPartitioner/Makefile.am +++ b/src/MEDPartitioner/Makefile.am @@ -121,7 +121,7 @@ medpartitioner_LDADD= $(libmedpartitioner_la_LDFLAGS) -lm libmedpartitioner.la medpartitioner_CXXFLAGS = @CXXTMPDPTHFLAGS@ if MED_ENABLE_PARMETIS - bin_PROGRAMS=medpartitioner_para + bin_PROGRAMS+=medpartitioner_para dist_medpartitioner_para_SOURCES= medpartitioner_para.cxx medpartitioner_para_CPPFLAGS= $(libmedpartitioner_la_CPPFLAGS) medpartitioner_para_LDADD= $(libmedpartitioner_la_LDFLAGS) -lm libmedpartitioner.la