From c55d48729efbea0f7065051cdab7305e167f20f1 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 7 Aug 2013 07:20:25 +0000 Subject: [PATCH] Generalization of unstructured grid supported by the remapper. --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 21 +++++- src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 2 + .../MEDCouplingNormalizedUnstructuredMesh.hxx | 6 +- .../MEDCouplingNormalizedUnstructuredMesh.txx | 65 ++++++++++++++----- src/MEDCoupling/MEDCouplingPointSet.hxx | 1 + src/MEDCoupling/MEDCouplingRemapper.cxx | 16 ++++- src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 5 ++ src/MEDCoupling/MEDCouplingUMeshDesc.hxx | 1 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 2 +- 9 files changed, 94 insertions(+), 25 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index d80bf9374..d65031154 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -679,6 +679,11 @@ int MEDCoupling1SGTUMesh::getNumberOfCells() const return nbOfTuples/nbOfNodesPerCell; } +int MEDCoupling1SGTUMesh::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + return getNumberOfNodesPerCell(); +} + int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception) { checkNonDynamicGeoType(); @@ -2053,7 +2058,7 @@ DataArrayInt *MEDCoupling1DGTUMesh::computeEffectiveNbOfNodesPerCell() const thr void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const { - int nbOfCells=getNumberOfCells();//performs checks + int nbOfCells(getNumberOfCells());//performs checks if(cellId>=0 && cellIdgetIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0); @@ -2065,7 +2070,19 @@ void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector& conn) } else { - std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !"; + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +int MEDCoupling1DGTUMesh::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + int nbOfCells(getNumberOfCells());//performs checks + if(cellId>=0 && cellIdgetIJ(cellId+1,0)-_conn_indx->getIJ(cellId,0); + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNumberOfNodesInCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index a11f3b770..690a2c37e 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -125,6 +125,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; + MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); // overload of MEDCoupling1GTUMesh MEDCOUPLING_EXPORT void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); @@ -198,6 +199,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; + MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); // overload of MEDCoupling1GTUMesh MEDCOUPLING_EXPORT void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.hxx b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.hxx index 8e8ffb622..7dfd3126c 100644 --- a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.hxx +++ b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.hxx @@ -25,7 +25,7 @@ namespace ParaMEDMEM { - class MEDCouplingUMesh; + class MEDCouplingPointSet; } template @@ -37,7 +37,7 @@ public: typedef int MyConnType; static const INTERP_KERNEL::NumberingPolicy My_numPol=INTERP_KERNEL::ALL_C_MODE; public: - MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingUMesh *mesh); + MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingPointSet *mesh); void getBoundingBox(double *boundingBox) const; INTERP_KERNEL::NormalizedCellType getTypeOfElement(int eltId) const; int getNumberOfNodesOfElement(int eltId) const; @@ -51,7 +51,7 @@ public: private: void prepare(); private: - const ParaMEDMEM::MEDCouplingUMesh *_mesh; + const ParaMEDMEM::MEDCouplingPointSet *_mesh; int *_conn_for_interp; int *_conn_index_for_interp; }; diff --git a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx index 95d74e589..eb9d2325d 100644 --- a/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx +++ b/src/MEDCoupling/MEDCouplingNormalizedUnstructuredMesh.txx @@ -17,18 +17,20 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // Author : Anthony Geay (CEA/DEN) + #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__ #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__ #include "MEDCouplingNormalizedUnstructuredMesh.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include template -MEDCouplingNormalizedUnstructuredMesh::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh) +MEDCouplingNormalizedUnstructuredMesh::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingPointSet *mesh):_mesh(mesh) { if(_mesh) _mesh->incrRef(); @@ -122,24 +124,53 @@ MEDCouplingNormalizedUnstructuredMesh::~MEDCouplingNormalizedU template void MEDCouplingNormalizedUnstructuredMesh::prepare() { - int nbOfCell=_mesh->getNumberOfCells(); - int initialConnSize=_mesh->getNodalConnectivity()->getNbOfElems(); - _conn_for_interp=new int[initialConnSize-nbOfCell]; - _conn_index_for_interp=new int[nbOfCell+1]; - _conn_index_for_interp[0]=0; - const int *work_conn=_mesh->getNodalConnectivity()->getConstPointer()+1; - const int *work_conn_index=_mesh->getNodalConnectivityIndex()->getConstPointer(); - int *work_conn_for_interp=_conn_for_interp; - int *work_conn_index_for_interp=_conn_index_for_interp; - for(int i=0;i(_mesh)); + if(m1) + { + int nbOfCell=m1->getNumberOfCells(); + int initialConnSize=m1->getNodalConnectivity()->getNbOfElems(); + _conn_for_interp=new int[initialConnSize-nbOfCell]; + _conn_index_for_interp=new int[nbOfCell+1]; + _conn_index_for_interp[0]=0; + const int *work_conn=m1->getNodalConnectivity()->getConstPointer()+1; + const int *work_conn_index=m1->getNodalConnectivityIndex()->getConstPointer(); + int *work_conn_for_interp=_conn_for_interp; + int *work_conn_index_for_interp=_conn_index_for_interp; + for(int i=0;i(_mesh)); + if(m2) + { + int nbOfCell(m2->getNumberOfCells()); + _conn_index_for_interp=new int[nbOfCell+1]; + const int *conni(m2->getNodalConnectivityIndex()->begin()); + std::copy(conni,conni+nbOfCell+1,_conn_index_for_interp); + _conn_for_interp=new int[m2->getNodalConnectivity()->getNumberOfTuples()]; + std::copy(m2->getNodalConnectivity()->begin(),m2->getNodalConnectivity()->end(),_conn_for_interp); + return ; + } + const ParaMEDMEM::MEDCoupling1SGTUMesh *m3(dynamic_cast(_mesh)); + if(m3) { - int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1; - work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp); - work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy; - work_conn_index++; - work_conn+=nbOfValsToCopy+1; - work_conn_index_for_interp++; + int nbOfCell(m3->getNumberOfCells()),nbNodesPerCell(m3->getNumberOfNodesPerCell()); + _conn_index_for_interp=new int[nbOfCell+1]; _conn_index_for_interp[0]=0; + int *work(_conn_index_for_interp); + for(int i=0;igetNodalConnectivity()->getNumberOfTuples()]; + std::copy(m3->getNodalConnectivity()->begin(),m3->getNodalConnectivity()->end(),_conn_for_interp); + return ; } + throw INTERP_KERNEL::Exception("MEDCouplingNormalizedUnstructuredMesh::prepare : Unrecognized unstructured mesh ! Type must be in MEDCouplingUMesh, MEDCoupling1DGTUMesh, MEDCoupling1SGTUMesh !"); } #endif diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index b6f5ada50..dae6c4925 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -116,6 +116,7 @@ namespace ParaMEDMEM virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; virtual DataArrayInt *findBoundaryNodes() const = 0; virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; + virtual int getNumberOfNodesInCell(int cellId) const = 0; virtual DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception) = 0; virtual void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const = 0; virtual void renumberNodesInConn(const int *newNodeNumbersO2N) = 0; diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 2843f8831..2879ada37 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -82,10 +82,22 @@ int MEDCouplingRemapper::prepareInterpKernelOnly() throw(INTERP_KERNEL::Exceptio int meshInterpType=((int)_src_ft->getMesh()->getType()*16)+(int)_target_ft->getMesh()->getType(); switch(meshInterpType) { + case 90: + case 91: + case 165: + case 181: + case 170: + case 171: + case 186: + case 187: case 85://Unstructured-Unstructured return prepareInterpKernelOnlyUU(); + case 167: + case 183: case 87://Unstructured-Cartesian return prepareInterpKernelOnlyUC(); + case 122: + case 123: case 117://Cartesian-Unstructured return prepareInterpKernelOnlyCU(); case 119://Cartesian-Cartesian @@ -289,8 +301,8 @@ void MEDCouplingRemapper::setInterpolationMatrixPolicy(int newInterpMatPol) thro int MEDCouplingRemapper::prepareInterpKernelOnlyUU() throw(INTERP_KERNEL::Exception) { - const MEDCouplingUMesh *src_mesh=static_cast(_src_ft->getMesh()); - const MEDCouplingUMesh *target_mesh=static_cast(_target_ft->getMesh()); + const MEDCouplingPointSet *src_mesh=static_cast(_src_ft->getMesh()); + const MEDCouplingPointSet *target_mesh=static_cast(_target_ft->getMesh()); std::string srcMeth,trgMeth; std::string method=checkAndGiveInterpolationMethodStr(srcMeth,trgMeth); const int srcMeshDim=src_mesh->getMeshDimension(); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 6f5a9ec2a..4301475f6 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -560,3 +560,8 @@ void MEDCouplingUMeshDesc::reprQuickOverview(std::ostream& stream) const throw(I { stream << "MEDCouplingUMeshDesc C++ instance at " << this << ". Name : \"" << getName() << "\"."; } + +int MEDCouplingUMeshDesc::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getNumberOfNodesInCell : not implemented yet !"); +} diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index e26b63d44..71e5e0f7d 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -57,6 +57,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *computeEffectiveNbOfNodesPerCell() 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 int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const { return UNSTRUCTURED_DESC; } diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index e39390b98..6f8a20de7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1150,6 +1150,7 @@ namespace ParaMEDMEM virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); static DataArrayDouble *MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception); static MEDCouplingPointSet *BuildInstanceFromMeshType(MEDCouplingMeshType type) throw(INTERP_KERNEL::Exception); + virtual int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) throw(INTERP_KERNEL::Exception); virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); @@ -1733,7 +1734,6 @@ namespace ParaMEDMEM void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true) throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); void setPartOfMySelf2(int start, int end, int step, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception); - int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); int getMeshLength() const throw(INTERP_KERNEL::Exception); void computeTypes() throw(INTERP_KERNEL::Exception); std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); -- 2.39.2