From b643303db59e6f5ed2401a0d64beb2f5571c84c6 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 19 Jul 2013 10:29:10 +0000 Subject: [PATCH] On the highway to MEDReader --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 99 +++++++++++++++++++++++- src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 3 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 5 +- 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 8ac12872f..8a8034b61 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -46,6 +46,20 @@ MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const char *name, INTERP_KERNEL::N return MEDCoupling1DGTUMesh::New(name,type); } +MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh is null !"); + std::set gts(m->getAllGeoTypes()); + if(gts.size()!=1) + throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh must have exactly one geometric type !"); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*gts.begin()); + if(!cm.isDynamic()) + return MEDCoupling1SGTUMesh::New(m); + else + return MEDCoupling1DGTUMesh::New(m); +} + const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception) { return *_cm; @@ -384,7 +398,7 @@ MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::v 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)); + MEDCouplingAutoRefCountObjectPtr ret(MEDCouplingUMesh::New(firstPart->getName(),meshDim)); ret->setDescription(firstPart->getDescription()); ret->setCoords(coords); int nbOfCells(0),connSize(0); for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++) @@ -464,6 +478,43 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL: return new MEDCoupling1SGTUMesh(name,cm); } +MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh is null !"); + std::set gts(m->getAllGeoTypes()); + if(gts.size()!=1) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh must have exactly one geometric type !"); + int geoType((int)*gts.begin()); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(m->getName(),*gts.begin())); + ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription()); + int nbCells(m->getNumberOfCells()); + int nbOfNodesPerCell(ret->getNumberOfNodesPerCell()); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); conn->alloc(nbCells*nbOfNodesPerCell,1); + int *c(conn->getPointer()); + const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin()); + for(int i=0;isetNodalConnectivity(conn); + return ret.retn(); +} + MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::clone(bool recDeepCpy) const { return new MEDCoupling1SGTUMesh(*this,recDeepCpy); @@ -1273,7 +1324,7 @@ void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do MEDCouplingPointSet::checkFastEquivalWith(other,prec); const MEDCoupling1SGTUMesh *otherC=dynamic_cast(other); if(!otherC) - throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !"); + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single static geometric type !"); const DataArrayInt *c1(_conn),*c2(otherC->_conn); if(c1==c2) return; @@ -1406,7 +1457,7 @@ void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const in } } -//== find static tony +//== MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception) { @@ -1571,7 +1622,7 @@ void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do MEDCouplingPointSet::checkFastEquivalWith(other,prec); const MEDCoupling1DGTUMesh *otherC=dynamic_cast(other); if(!otherC) - throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !"); + throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single dynamic geometric type !"); const DataArrayInt *c1(_conn),*c2(otherC->_conn); if(c1!=c2) { @@ -2603,3 +2654,43 @@ DataArrayInt *MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds(const std: } return ret.retn(); } + +MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh is null !"); + std::set gts(m->getAllGeoTypes()); + if(gts.size()!=1) + throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh must have exactly one geometric type !"); + int geoType((int)*gts.begin()); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1DGTUMesh::New(m->getName(),*gts.begin())); + ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription()); + int nbCells(m->getNumberOfCells()); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()); + conn->alloc(m->getMeshLength()-nbCells,1); connI->alloc(nbCells+1,1); + int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0; + const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin()); + for(int i=0;i=1) + { + c=std::copy(cin+ciin[0]+1,cin+ciin[1],c); + ci[1]=ci[0]+ciin[1]-ciin[0]-1; + } + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret->setNodalConnectivity(conn,connI); + return ret.retn(); +} diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 2de8afa19..748992d3f 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -36,6 +36,7 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static MEDCoupling1GTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCoupling1GTUMesh *New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT const INTERP_KERNEL::CellModel& getCellModel() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT INTERP_KERNEL::NormalizedCellType getCellModelEnum() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMeshDimension() const; @@ -81,6 +82,7 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static MEDCoupling1SGTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCoupling1SGTUMesh *New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *clone(bool recDeepCpy) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception); // overload of TimeLabel and RefCountObject @@ -147,6 +149,7 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static MEDCoupling1DGTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static MEDCoupling1DGTUMesh *New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCoupling1DGTUMesh *clone(bool recDeepCpy) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception); // overload of TimeLabel and RefCountObject diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index f4d1a0357..dd1ae5fbc 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2761,6 +2761,7 @@ namespace ParaMEDMEM { public: static MEDCoupling1GTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static MEDCoupling1GTUMesh *New(const MEDCouplingUMesh *m) 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); @@ -2795,7 +2796,8 @@ namespace ParaMEDMEM class MEDCoupling1SGTUMesh : public ParaMEDMEM::MEDCoupling1GTUMesh { public: - static MEDCoupling1GTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static MEDCoupling1SGTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static MEDCoupling1SGTUMesh *New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); void setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception); int getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception); static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception); @@ -2843,6 +2845,7 @@ namespace ParaMEDMEM { public: static MEDCoupling1DGTUMesh *New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static MEDCoupling1DGTUMesh *New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception); void setNodalConnectivity(DataArrayInt *nodalConn, DataArrayInt *nodalConnIndex) throw(INTERP_KERNEL::Exception); MEDCoupling1DGTUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); bool isPacked() const throw(INTERP_KERNEL::Exception); -- 2.39.2