From e46bd3d7e93a54a548333bff20f0c038ef3055de Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 19 Jul 2013 09:44:52 +0000 Subject: [PATCH] On the highway to MEDReader --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 97 +++++++++++++++++++++--- src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 4 +- src/MEDCoupling_Swig/MEDCouplingCommon.i | 34 ++++----- 3 files changed, 105 insertions(+), 30 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 76f5a73d0..8ac12872f 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -350,6 +350,91 @@ void MEDCoupling1GTUMesh::findCommonCells(int compType, int startCellId, DataArr m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr); } +int MEDCoupling1GTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception) +{ + const DataArrayInt *c1(getNodalConnectivity()); + if(!c1) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : no connectivity set !"); + if(c1->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !"); + if(!c1->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !"); + return c1->getNumberOfTuples(); +} + +/*! + * This method aggregates all the meshes in \a parts to put them in a single unstructured mesh (those returned). + * The order of cells is the returned instance is those in the order of instances in \a parts. + * + * \param [in] parts - all not null parts of single geo type meshes to be aggreagated having the same mesh dimension and same coordinates. + * \return MEDCouplingUMesh * - new object to be dealt by the caller. + * + * \throw If one element is null in \a parts. + * \throw If not all the parts do not have the same mesh dimension. + * \throw If not all the parts do not share the same coordinates. + * \throw If not all the parts have their connectivity set properly. + * \throw If \a parts is empty. + */ +MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception) +{ + if(parts.empty()) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : input parts vector is empty !"); + const MEDCoupling1GTUMesh *firstPart(parts[0]); + if(!firstPart) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : the first instance in input parts is null !"); + const DataArrayDouble *coords(firstPart->getCoords()); + int meshDim(firstPart->getMeshDimension()); + MEDCouplingAutoRefCountObjectPtr ret(MEDCouplingUMesh::New(firstPart->getName(),meshDim)); + ret->setCoords(coords); + int nbOfCells(0),connSize(0); + for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++) + { + if(!(*it)) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of null pointer in input vector !"); + if((*it)->getMeshDimension()!=meshDim) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances in input vector must have same mesh dimension !"); + if((*it)->getCoords()!=coords) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances must share the same coordinates pointer !"); + nbOfCells+=(*it)->getNumberOfCells(); + connSize+=(*it)->getNodalConnectivityLength(); + } + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()); + connI->alloc(nbOfCells+1,1); conn->alloc(connSize+nbOfCells,1); + int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0; + for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++) + { + int curNbCells((*it)->getNumberOfCells()); + int geoType((int)(*it)->getCellModelEnum()); + const int *cinPtr((*it)->getNodalConnectivity()->begin()); + const MEDCoupling1SGTUMesh *ps(dynamic_cast(*it)); + const MEDCoupling1DGTUMesh *pd(dynamic_cast(*it)); + if(ps && !pd) + { + int nNodesPerCell(ps->getNumberOfNodesPerCell()); + for(int i=0;igetNodalConnectivityIndex()->begin()); + for(int i=0;isetConnectivity(conn,connI,true); + return ret.retn(); +} + //== MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn) @@ -544,18 +629,6 @@ int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::E return (int)_cm->getNumberOfNodes(); } -int MEDCoupling1SGTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception) -{ - const DataArrayInt *c1(_conn); - if(!c1) - throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : no connectivity set !"); - if(c1->getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !"); - if(!c1->isAllocated()) - throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !"); - return c1->getNumberOfTuples(); -} - DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) { checkNonDynamicGeoType(); diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 7de7b997b..2de8afa19 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -50,6 +50,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); // MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; + MEDCOUPLING_EXPORT int getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; MEDCOUPLING_EXPORT void checkCoherency() const throw(INTERP_KERNEL::Exception); @@ -64,9 +65,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *findBoundaryNodes() const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; MEDCOUPLING_EXPORT void findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCouplingUMesh *AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception); public: MEDCOUPLING_EXPORT virtual void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCOUPLING_EXPORT MEDCoupling1GTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm); MEDCOUPLING_EXPORT MEDCoupling1GTUMesh(const MEDCoupling1GTUMesh& other, bool recDeepCpy); @@ -121,7 +124,6 @@ namespace ParaMEDMEM public://specific MEDCOUPLING_EXPORT void setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(std::vector& a) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index bee74173e..f4d1a0357 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -444,13 +444,13 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMeshCellByTypeEntry::__iter__; %newobject ParaMEDMEM::MEDCouplingUMeshCellEntry::__iter__; %newobject ParaMEDMEM::MEDCoupling1GTUMesh::New; +%newobject ParaMEDMEM::MEDCoupling1GTUMesh::getNodalConnectivity; +%newobject ParaMEDMEM::MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh; %newobject ParaMEDMEM::MEDCoupling1SGTUMesh::New; -%newobject ParaMEDMEM::MEDCoupling1SGTUMesh::getNodalConnectivity; %newobject ParaMEDMEM::MEDCoupling1SGTUMesh::buildSetInstanceFromThis; %newobject ParaMEDMEM::MEDCoupling1SGTUMesh::Merge1SGTUMeshes; %newobject ParaMEDMEM::MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords; %newobject ParaMEDMEM::MEDCoupling1DGTUMesh::New; -%newobject ParaMEDMEM::MEDCoupling1DGTUMesh::getNodalConnectivity; %newobject ParaMEDMEM::MEDCoupling1DGTUMesh::getNodalConnectivityIndex; %newobject ParaMEDMEM::MEDCoupling1DGTUMesh::buildSetInstanceFromThis; %newobject ParaMEDMEM::MEDCoupling1DGTUMesh::Merge1DGTUMeshes; @@ -2762,6 +2762,7 @@ namespace ParaMEDMEM public: static MEDCoupling1GTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getCellModelEnum() const throw(INTERP_KERNEL::Exception); + int getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception); virtual void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); %extend { @@ -2772,6 +2773,20 @@ namespace ParaMEDMEM const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); self->insertNextCell(tmp,tmp+szArr); } + + virtual DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret=self->getNodalConnectivity(); + if(ret) ret->incrRef(); + return ret; + } + + static MEDCouplingUMesh *AggregateOnSameCoordsToUMesh(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector< const MEDCoupling1GTUMesh *> parts; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1GTUMesh,"MEDCoupling1GTUMesh",parts); + return MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(parts); + } } }; @@ -2782,7 +2797,6 @@ namespace ParaMEDMEM public: static MEDCoupling1GTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); void setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception); - int getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception); int getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception); static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception); MEDCoupling1SGTUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); @@ -2805,13 +2819,6 @@ namespace ParaMEDMEM return oss.str(); } - DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret=self->getNodalConnectivity(); - if(ret) ret->incrRef(); - return ret; - } - static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -2858,13 +2865,6 @@ namespace ParaMEDMEM return oss.str(); } - DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret=self->getNodalConnectivity(); - if(ret) ret->incrRef(); - return ret; - } - DataArrayInt *getNodalConnectivityIndex() const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret=self->getNodalConnectivityIndex(); -- 2.39.2