X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCoupling1GTUMesh.cxx;h=0cf66514f21a3c576428211fdef0877b2ad383c7;hb=e1769d9778b9b8ce1c884846d4c895a6d31be112;hp=2f88693add84404ac9a12e91572a694d6f663b4b;hpb=7fc13e546d61c65f725e76727c5a99b1f7282b82;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 2f88693ad..0cf66514f 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -26,6 +26,10 @@ using namespace ParaMEDMEM; +MEDCoupling1GTUMesh::MEDCoupling1GTUMesh() +{ +} + MEDCoupling1GTUMesh::MEDCoupling1GTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):_cm(&cm) { setName(name); @@ -46,6 +50,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; @@ -120,13 +138,13 @@ std::set MEDCoupling1GTUMesh::getAllGeoTypes( * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how * \a this is composed in cell types. * The returned array is of size 3*n where n is the number of different types present in \a this. - * For every k in [0,n] ret[3*k+2]==0 because it has no sense here. + * For every k in [0,n] ret[3*k+2]==-1 because it has no sense here. * This parameter is kept only for compatibility with other methode listed above. */ std::vector MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) { std::vector ret(3); - ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=0; + ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=-1; return ret; } @@ -350,6 +368,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().c_str(),meshDim)); ret->setDescription(firstPart->getDescription().c_str()); + 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) @@ -366,6 +469,15 @@ MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const char *name, const INTERP_KERNEL { } +MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh() +{ +} + +MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New() +{ + return new MEDCoupling1SGTUMesh; +} + MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception) { if(type==INTERP_KERNEL::NORM_ERROR) @@ -379,11 +491,64 @@ 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().c_str(),*gts.begin())); + ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str()); + 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); } +/*! + * This method behaves mostly like MEDCoupling1SGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied. + * The coordinates are shared between \a this and the returned instance. + * + * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes) + * \sa MEDCoupling1SGTUMesh::deepCpy + */ +MEDCouplingPointSet *MEDCoupling1SGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception) +{ + checkCoherency(); + MEDCouplingAutoRefCountObjectPtr ret(clone(false)); + MEDCouplingAutoRefCountObjectPtr c(_conn->deepCpy()); + ret->setNodalConnectivity(c); + return ret.retn(); +} + void MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception) { if(!other) @@ -464,9 +629,8 @@ bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *o return true; } -void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +void MEDCoupling1SGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception) { - MEDCouplingPointSet::checkCoherency(); const DataArrayInt *c1(_conn); if(c1) { @@ -480,6 +644,12 @@ void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !"); } +void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingPointSet::checkCoherency(); + checkCoherencyOfConnectivity(); +} + void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception) { checkCoherency(); @@ -522,22 +692,15 @@ int MEDCoupling1SGTUMesh::getNumberOfCells() const return nbOfTuples/nbOfNodesPerCell; } -int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +int MEDCoupling1SGTUMesh::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception) { - checkNonDynamicGeoType(); - return (int)_cm->getNumberOfNodes(); + return getNumberOfNodesPerCell(); } -int MEDCoupling1SGTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception) +int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() 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(); + checkNonDynamicGeoType(); + return (int)_cm->getNumberOfNodes(); } DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) @@ -558,6 +721,23 @@ DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfFacesPerCell() const throw(INTERP return ret.retn(); } +DataArrayInt *MEDCoupling1SGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +{ + checkNonDynamicGeoType(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + int nbCells(getNumberOfCells()); + ret->alloc(nbCells,1); + int *retPtr(ret->getPointer()); + int nbNodesPerCell(getNumberOfNodesPerCell()); + const int *conn(_conn->begin()); + for(int i=0;i s(conn,conn+nbNodesPerCell); + *retPtr=(int)s.size(); + } + return ret.retn(); +} + void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const { int sz=getNumberOfNodesPerCell(); @@ -762,7 +942,7 @@ MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *ot MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) { - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(getName(),getMeshDimension()); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension()); ret->setCoords(getCoords()); const int *nodalConn=_conn->begin(); int nbCells=getNumberOfCells(); @@ -982,7 +1162,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector ret(new MEDCoupling1SGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm)); ret->setCoords(_coords); std::size_t nbOfElemsRet=std::distance(begin,end); const int *inConn=_conn->getConstPointer(); @@ -1008,7 +1188,7 @@ MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int star { int ncell=getNumberOfCells(); int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : "); - MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1SGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm)); ret->setCoords(_coords); const int *inConn=_conn->getConstPointer(); int sz=getNumberOfNodesPerCell(); @@ -1030,9 +1210,28 @@ MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int star return ret.retn(); } +void MEDCoupling1SGTUMesh::computeNodeIdsAlg(std::vector& nodeIdsInUse) const throw(INTERP_KERNEL::Exception) +{ + int sz((int)nodeIdsInUse.size()); + int nbCells(getNumberOfCells()); + int nbOfNodesPerCell(getNumberOfNodesPerCell()); + const int *w(_conn->begin()); + for(int i=0;i=0 && *w ret(new MEDCoupling1SGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm)); MEDCouplingAutoRefCountObjectPtr tmp1; const DataArrayInt *nodalConn(_conn); if(!nodalConn) @@ -1169,6 +1368,94 @@ bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector& tinyInfo) const throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !"); } +void MEDCoupling1SGTUMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const +{ + int it,order; + double time=getTime(it,order); + tinyInfo.clear(); tinyInfoD.clear(); littleStrings.clear(); + // + littleStrings.push_back(getName()); + littleStrings.push_back(getDescription()); + littleStrings.push_back(getTimeUnit()); + // + std::vector littleStrings2,littleStrings3; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationStrInformation(littleStrings2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationStrInformation(littleStrings3); + int sz0((int)littleStrings2.size()),sz1((int)littleStrings3.size()); + littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end()); + littleStrings.insert(littleStrings.end(),littleStrings3.begin(),littleStrings3.end()); + // + tinyInfo.push_back(getCellModelEnum()); + tinyInfo.push_back(it); + tinyInfo.push_back(order); + std::vector tinyInfo2,tinyInfo3; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationIntInformation(tinyInfo2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationIntInformation(tinyInfo3); + int sz2((int)tinyInfo2.size()),sz3((int)tinyInfo3.size()); + tinyInfo.push_back(sz0); tinyInfo.push_back(sz1); tinyInfo.push_back(sz2); tinyInfo.push_back(sz3); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo3.begin(),tinyInfo3.end()); + // + tinyInfoD.push_back(time); +} + +void MEDCoupling1SGTUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const +{ + std::vector tinyInfo2(tinyInfo.begin()+7,tinyInfo.begin()+7+tinyInfo[5]); + std::vector tinyInfo1(tinyInfo.begin()+7+tinyInfo[5],tinyInfo.begin()+7+tinyInfo[5]+tinyInfo[6]); + a1->resizeForUnserialization(tinyInfo1); + a2->resizeForUnserialization(tinyInfo2); +} + +void MEDCoupling1SGTUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + int sz(0); + if((const DataArrayInt *)_conn) + if(_conn->isAllocated()) + sz=_conn->getNbOfElems(); + a1=DataArrayInt::New(); + a1->alloc(sz,1); + if(sz!=0 && (const DataArrayInt *)_conn) + std::copy(_conn->begin(),_conn->end(),a1->getPointer()); + sz=0; + if((const DataArrayDouble *)_coords) + if(_coords->isAllocated()) + sz=_coords->getNbOfElems(); + a2=DataArrayDouble::New(); + a2->alloc(sz,1); + if(sz!=0 && (const DataArrayDouble *)_coords) + std::copy(_coords->begin(),_coords->end(),a2->getPointer()); +} + +void MEDCoupling1SGTUMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings) +{ + INTERP_KERNEL::NormalizedCellType gt((INTERP_KERNEL::NormalizedCellType)tinyInfo[0]); + _cm=&INTERP_KERNEL::CellModel::GetCellModel(gt); + setName(littleStrings[0].c_str()); + setDescription(littleStrings[1].c_str()); + setTimeUnit(littleStrings[2].c_str()); + setTime(tinyInfoD[0],tinyInfo[1],tinyInfo[2]); + int sz0(tinyInfo[3]),sz1(tinyInfo[4]),sz2(tinyInfo[5]),sz3(tinyInfo[6]); + // + _coords=DataArrayDouble::New(); + std::vector tinyInfo2(tinyInfo.begin()+7,tinyInfo.begin()+7+sz2); + _coords->resizeForUnserialization(tinyInfo2); + std::copy(a2->begin(),a2->end(),_coords->getPointer()); + _conn=DataArrayInt::New(); + std::vector tinyInfo3(tinyInfo.begin()+7+sz2,tinyInfo.begin()+7+sz2+sz3); + _conn->resizeForUnserialization(tinyInfo3); + std::copy(a1->begin(),a1->end(),_conn->getPointer()); + std::vector littleStrings2(littleStrings.begin()+3,littleStrings.begin()+3+sz0); + _coords->finishUnserialization(tinyInfo2,littleStrings2); + std::vector littleStrings3(littleStrings.begin()+3+sz0,littleStrings.begin()+3+sz0+sz1); + _conn->finishUnserialization(tinyInfo3,littleStrings3); +} + /*! * Checks if \a this and \a other meshes are geometrically equivalent with high * probability, else an exception is thrown. The meshes are considered equivalent if @@ -1184,7 +1471,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; @@ -1317,7 +1604,234 @@ void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const in } } -//== find static tony +/*! + * This method builds the dual mesh of \a this and returns it. + * + * \return MEDCoupling1SGTUMesh * - newly object created to be managed by the caller. + * \throw If \a this is not a mesh containing only simplex cells. + * \throw If \a this is not correctly allocated (coordinates and connectivities have to be correctly set !). + * \throw If at least one node in \a this is orphan (without any simplex cell lying on it !) + */ +MEDCoupling1GTUMesh *MEDCoupling1SGTUMesh::computeDualMesh() const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm(getCellModel()); + if(!cm.isSimplex()) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh : this mesh is not a simplex mesh ! Please invoke simplexize of tetrahedrize on this before calling this method !"); + switch(getMeshDimension()) + { + case 3: + return computeDualMesh3D(); + case 2: + return computeDualMesh2D(); + default: + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh : meshdimension must be in [2,3] !"); + } +} + +MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTERP_KERNEL::Exception) +{ + static const int DUAL_TETRA_0[36]={ + 4,1,0, 6,0,3, 7,3,1, + 4,0,1, 5,2,0, 8,1,2, + 6,3,0, 5,0,2, 9,2,3, + 7,1,3, 9,3,2, 8,2,1 + }; + static const int DUAL_TETRA_1[36]={ + 8,4,10, 11,5,8, 10,7,11, + 9,4,8, 8,5,12, 12,6,9, + 10,4,9, 9,6,13, 13,7,10, + 12,5,11, 13,6,12, 11,7,13 + }; + static const int FACEID_NOT_SH_NODE[4]={2,3,1,0}; + if(getCellModelEnum()!=INTERP_KERNEL::NORM_TETRA4) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh3D : only TETRA4 supported !"); + checkFullyDefined(); + MEDCouplingAutoRefCountObjectPtr thisu(buildUnstructured()); + MEDCouplingAutoRefCountObjectPtr revNodArr(DataArrayInt::New()),revNodIArr(DataArrayInt::New()); + thisu->getReverseNodalConnectivity(revNodArr,revNodIArr); + const int *revNod(revNodArr->begin()),*revNodI(revNodIArr->begin()),*nodal(_conn->begin()); + MEDCouplingAutoRefCountObjectPtr d1Arr(DataArrayInt::New()),di1Arr(DataArrayInt::New()),rd1Arr(DataArrayInt::New()),rdi1Arr(DataArrayInt::New()); + MEDCouplingAutoRefCountObjectPtr edges(thisu->explode3DMeshTo1D(d1Arr,di1Arr,rd1Arr,rdi1Arr)); + const int *d1(d1Arr->begin()); + MEDCouplingAutoRefCountObjectPtr d2Arr(DataArrayInt::New()),di2Arr(DataArrayInt::New()),rd2Arr(DataArrayInt::New()),rdi2Arr(DataArrayInt::New()); + MEDCouplingAutoRefCountObjectPtr faces(thisu->buildDescendingConnectivity(d2Arr,di2Arr,rd2Arr,rdi2Arr)); thisu=0; + const int *d2(d2Arr->begin()),*rd2(rd2Arr->begin()),*rdi2(rdi2Arr->begin()); + MEDCouplingAutoRefCountObjectPtr edgesBaryArr(edges->getBarycenterAndOwner()),facesBaryArr(faces->getBarycenterAndOwner()),baryArr(getBarycenterAndOwner()); + const int nbOfNodes(getNumberOfNodes()),offset0(nbOfNodes+faces->getNumberOfCells()),offset1(offset0+edges->getNumberOfCells()); + edges=0; faces=0; + std::vector v(4); v[0]=getCoords(); v[1]=facesBaryArr; v[2]=edgesBaryArr; v[3]=baryArr; + MEDCouplingAutoRefCountObjectPtr zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0; facesBaryArr=0; + std::string name("DualOf_"); name+=getName(); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYHED)); ret->setCoords(zeArr); + MEDCouplingAutoRefCountObjectPtr cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1); + for(int i=0;ipushBackSilent(-1); + int tmp[14]; + // + tmp[0]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+0]-4]+offset0; tmp[1]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+1]]+nbOfNodes; + tmp[2]=curCellId+offset1; tmp[3]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+2]]+nbOfNodes; + tmp[4]=-1; + tmp[5]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+3]-4]+offset0; tmp[6]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+4]]+nbOfNodes; + tmp[7]=curCellId+offset1; tmp[8]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+5]]+nbOfNodes; + tmp[9]=-1; + tmp[10]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+6]-4]+offset0; tmp[11]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+7]]+nbOfNodes; + tmp[12]=curCellId+offset1; tmp[13]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+8]]+nbOfNodes; + cArr->insertAtTheEnd(tmp,tmp+14); + int kk(0); + for(int k=0;k<4;k++) + { + if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k) + { + const int *faceId(d2+4*curCellId+k); + if(rdi2[*faceId+1]-rdi2[*faceId]==1) + { + int tmp2[5]; tmp2[0]=-1; tmp2[1]=i; + tmp2[2]=d1[6*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+0]-8]+offset0; + tmp2[3]=d2[4*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+1]-4]+nbOfNodes; + tmp2[4]=d1[6*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+2]-8]+offset0; + cArr->insertAtTheEnd(tmp2,tmp2+5); + } + kk++; + } + } + } + ciArr->setIJ(i+1,0,cArr->getNumberOfTuples()); + } + ret->setNodalConnectivity(cArr,ciArr); + return ret.retn(); +} + +MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTERP_KERNEL::Exception) +{ + static const int DUAL_TRI_0[6]={0,2, 1,0, 2,1}; + static const int DUAL_TRI_1[6]={-3,+5, +3,-4, +4,-5}; + static const int FACEID_NOT_SH_NODE[3]={1,2,0}; + if(getCellModelEnum()!=INTERP_KERNEL::NORM_TRI3) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh2D : only TRI3 supported !"); + checkFullyDefined(); + MEDCouplingAutoRefCountObjectPtr thisu(buildUnstructured()); + MEDCouplingAutoRefCountObjectPtr revNodArr(DataArrayInt::New()),revNodIArr(DataArrayInt::New()); + thisu->getReverseNodalConnectivity(revNodArr,revNodIArr); + const int *revNod(revNodArr->begin()),*revNodI(revNodIArr->begin()),*nodal(_conn->begin()); + MEDCouplingAutoRefCountObjectPtr d2Arr(DataArrayInt::New()),di2Arr(DataArrayInt::New()),rd2Arr(DataArrayInt::New()),rdi2Arr(DataArrayInt::New()); + MEDCouplingAutoRefCountObjectPtr edges(thisu->buildDescendingConnectivity(d2Arr,di2Arr,rd2Arr,rdi2Arr)); thisu=0; + const int *d2(d2Arr->begin()),*rd2(rd2Arr->begin()),*rdi2(rdi2Arr->begin()); + MEDCouplingAutoRefCountObjectPtr edgesBaryArr(edges->getBarycenterAndOwner()),baryArr(getBarycenterAndOwner()); + const int nbOfNodes(getNumberOfNodes()),offset0(nbOfNodes+edges->getNumberOfCells()); + edges=0; + std::vector v(3); v[0]=getCoords(); v[1]=edgesBaryArr; v[2]=baryArr; + MEDCouplingAutoRefCountObjectPtr zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0; + std::string name("DualOf_"); name+=getName(); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYGON)); ret->setCoords(zeArr); + MEDCouplingAutoRefCountObjectPtr cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1); + for(int i=0;i > polyg; + for(int j=0;j locV(3); + locV[0]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+0]]+nbOfNodes; locV[1]=curCellId+offset0; locV[2]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+1]]+nbOfNodes; + polyg.push_back(locV); + int kk(0); + for(int k=0;k<3;k++) + { + if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k) + { + const int *edgeId(d2+3*curCellId+k); + if(rdi2[*edgeId+1]-rdi2[*edgeId]==1) + { + std::vector locV2(2); + int zeLocEdgeIdRel(DUAL_TRI_1[2*nodePosInCurCell+kk]); + if(zeLocEdgeIdRel>0) + { locV2[0]=d2[3*curCellId+zeLocEdgeIdRel-3]+nbOfNodes; locV2[1]=i; } + else + { locV2[0]=i; locV2[1]=d2[3*curCellId-zeLocEdgeIdRel-3]+nbOfNodes; } + polyg.push_back(locV2); + } + kk++; + } + } + } + std::vector zePolyg(MEDCoupling1DGTUMesh::BuildAPolygonFromParts(polyg)); + cArr->insertAtTheEnd(zePolyg.begin(),zePolyg.end()); + ciArr->setIJ(i+1,0,cArr->getNumberOfTuples()); + } + ret->setNodalConnectivity(cArr,ciArr); + return ret.retn(); +} + +/*! + * This method aggregate the bbox of each cell and put it into bbox + * + * \return DataArrayDouble * - newly created object (to be managed by the caller) \a this number of cells tuples and 2*spacedim components. + * + * \throw If \a this is not fully set (coordinates and connectivity). + * \throw If a cell in \a this has no valid nodeId. + */ +DataArrayDouble *MEDCoupling1SGTUMesh::getBoundingBoxForBBTree() const +{ + int spaceDim(getSpaceDimension()),nbOfCells(getNumberOfCells()),nbOfNodes(getNumberOfNodes()),nbOfNodesPerCell(getNumberOfNodesPerCell()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); ret->alloc(nbOfCells,2*spaceDim); + double *bbox(ret->getPointer()); + for(int i=0;i::max(); + bbox[2*i+1]=-std::numeric_limits::max(); + } + const double *coordsPtr(_coords->getConstPointer()); + const int *conn(_conn->getConstPointer()); + for(int i=0;i=0 && nodeId ret(clone(false)); + MEDCouplingAutoRefCountObjectPtr c(_conn->deepCpy()),ci(_conn_indx->deepCpy()); + ret->setNodalConnectivity(c,ci); + return ret.retn(); +} + void MEDCoupling1DGTUMesh::updateTime() const { MEDCoupling1GTUMesh::updateTime(); @@ -1466,7 +2000,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) { @@ -1493,14 +2027,8 @@ void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do } } -/*! - * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated. - * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one. - * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array. - */ -void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +void MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception) { - MEDCouplingPointSet::checkCoherency(); const DataArrayInt *c1(_conn); if(c1) { @@ -1546,11 +2074,22 @@ void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception int szOfC1Exp=_conn_indx->back(); if(sz2getNumberOfTuples() << " !"; + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } +/*! + * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated. + * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one. + * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array. + */ +void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingPointSet::checkCoherency(); + checkCoherencyOfConnectivity(); +} + void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception) { checkCoherency(); @@ -1579,7 +2118,7 @@ void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL int MEDCoupling1DGTUMesh::getNumberOfCells() const { - checkCoherency();//do not remove + checkCoherencyOfConnectivity();//do not remove return _conn_indx->getNumberOfTuples()-1; } @@ -1637,9 +2176,44 @@ DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfFacesPerCell() const throw(INTERP return ret.retn(); } +/*! + * This method computes effective number of nodes per cell. That is to say nodes appearing several times in nodal connectivity of a cell, + * will be counted only once here whereas it will be counted several times in MEDCoupling1DGTUMesh::computeNbOfNodesPerCell method. + * + * \return DataArrayInt * - new object to be deallocated by the caller. + * \sa MEDCoupling1DGTUMesh::computeNbOfNodesPerCell + */ +DataArrayInt *MEDCoupling1DGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +{ + checkCoherency(); + _conn_indx->checkMonotonic(true); + int nbOfCells(_conn_indx->getNumberOfTuples()-1); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(nbOfCells,1); + int *retPtr(ret->getPointer()); + const int *ci(_conn_indx->begin()),*c(_conn->begin()); + if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED) + { + for(int i=0;i s(c+ci[0],c+ci[1]); + *retPtr=(int)s.size(); + } + } + else + { + for(int i=0;i s(c+ci[0],c+ci[1]); s.erase(-1); + *retPtr=(int)s.size(); + } + } + return ret.retn(); +} + 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); @@ -1651,7 +2225,23 @@ 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 && cellIdbegin()); + int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0); + return stp-strt-std::count(conn+strt,conn+stp,-1); + } + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNumberOfNodesInCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -1741,7 +2331,7 @@ DataArrayDouble *MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell() cons for(int i=0;i=nodali[1])// >= to avoid division by 0. + if(nodali[0]= to avoid division by 0. { for(int j=nodali[0];j=nodali[1])// >= to avoid division by 0. + if(nodali[0]= to avoid division by 0. { int nbOfNod=0; for(int j=nodali[0];jcheckAndPreparePermutation(); // + const int *o2nPtr=o2n->getPointer(); const int *conn=_conn->begin(),*conni=_conn_indx->begin(); - MEDCouplingAutoRefCountObjectPtr n2o=o2n->invertArrayO2N2N2O(nbCells); - const int *n2oPtr=n2o->begin(); MEDCouplingAutoRefCountObjectPtr newConn=DataArrayInt::New(); MEDCouplingAutoRefCountObjectPtr newConnI=DataArrayInt::New(); newConn->alloc(_conn->getNumberOfTuples(),1); newConnI->alloc(nbCells,1); @@ -1821,9 +2410,10 @@ void MEDCoupling1DGTUMesh::renumberCells(const int *old2NewBg, bool check) throw int *newC=newConn->getPointer(),*newCI=newConnI->getPointer(); for(int i=0;i=0) - newCI[n2oPtr[i]]=sz; + newCI[newPos]=sz; else { std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberCells : the index nodal array is invalid for cell #" << i << " !"; @@ -1835,10 +2425,11 @@ void MEDCoupling1DGTUMesh::renumberCells(const int *old2NewBg, bool check) throw for(int i=0;i ret=MEDCouplingUMesh::New(getName(),getMeshDimension()); + MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension()); ret->setCoords(getCoords()); const int *nodalConn=_conn->begin(),*nodalConnI=_conn_indx->begin(); int nbCells=getNumberOfCells();//checkCoherency @@ -1937,7 +2528,7 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords(const MED MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const { checkCoherency(); - MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm)); ret->setCoords(_coords); DataArrayInt *c=0,*ci=0; MEDCouplingUMesh::ExtractFromIndexedArrays(begin,end,_conn,_conn_indx,c,ci); @@ -1949,7 +2540,7 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const { checkCoherency(); - MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm)); ret->setCoords(_coords); DataArrayInt *c=0,*ci=0; MEDCouplingUMesh::ExtractFromIndexedArrays2(start,end,step,_conn,_conn_indx,c,ci); @@ -1958,6 +2549,25 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int star return ret.retn(); } +void MEDCoupling1DGTUMesh::computeNodeIdsAlg(std::vector& nodeIdsInUse) const throw(INTERP_KERNEL::Exception) +{ + int sz((int)nodeIdsInUse.size()); + int nbCells(getNumberOfCells()); + const int *w(_conn->begin()),*wi(_conn_indx->begin()); + for(int i=0;i=0 && *pt& tinyInfo) const throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEmptyMesh : not implemented yet !"); } +void MEDCoupling1DGTUMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const +{ + int it,order; + double time=getTime(it,order); + tinyInfo.clear(); tinyInfoD.clear(); littleStrings.clear(); + // + littleStrings.push_back(getName()); + littleStrings.push_back(getDescription()); + littleStrings.push_back(getTimeUnit()); + // + std::vector littleStrings2,littleStrings3,littleStrings4; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationStrInformation(littleStrings2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationStrInformation(littleStrings3); + if((const DataArrayInt *)_conn_indx) + _conn_indx->getTinySerializationStrInformation(littleStrings4); + int sz0((int)littleStrings2.size()),sz1((int)littleStrings3.size()),sz2((int)littleStrings4.size()); + littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end()); + littleStrings.insert(littleStrings.end(),littleStrings3.begin(),littleStrings3.end()); + littleStrings.insert(littleStrings.end(),littleStrings4.begin(),littleStrings4.end()); + // + tinyInfo.push_back(getCellModelEnum()); + tinyInfo.push_back(it); + tinyInfo.push_back(order); + std::vector tinyInfo2,tinyInfo3,tinyInfo4; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationIntInformation(tinyInfo2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationIntInformation(tinyInfo3); + if((const DataArrayInt *)_conn_indx) + _conn_indx->getTinySerializationIntInformation(tinyInfo4); + int sz3((int)tinyInfo2.size()),sz4((int)tinyInfo3.size()),sz5((int)tinyInfo4.size()); + tinyInfo.push_back(sz0); tinyInfo.push_back(sz1); tinyInfo.push_back(sz2); tinyInfo.push_back(sz3); tinyInfo.push_back(sz4); tinyInfo.push_back(sz5); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo3.begin(),tinyInfo3.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo4.begin(),tinyInfo4.end()); + // + tinyInfoD.push_back(time); +} + +void MEDCoupling1DGTUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const +{ + std::vector tinyInfo2(tinyInfo.begin()+9,tinyInfo.begin()+9+tinyInfo[6]); + std::vector tinyInfo1(tinyInfo.begin()+9+tinyInfo[6],tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7]); + std::vector tinyInfo12(tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7],tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7]+tinyInfo[8]); + MEDCouplingAutoRefCountObjectPtr p1(DataArrayInt::New()); p1->resizeForUnserialization(tinyInfo1); + MEDCouplingAutoRefCountObjectPtr p2(DataArrayInt::New()); p2->resizeForUnserialization(tinyInfo12); + std::vector v(2); v[0]=p1; v[1]=p2; + p2=DataArrayInt::Aggregate(v); + a2->resizeForUnserialization(tinyInfo2); + a1->alloc(p2->getNbOfElems(),1); +} + +void MEDCoupling1DGTUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + int sz(0); + if((const DataArrayInt *)_conn) + if(_conn->isAllocated()) + sz=_conn->getNbOfElems(); + if((const DataArrayInt *)_conn_indx) + if(_conn_indx->isAllocated()) + sz+=_conn_indx->getNbOfElems(); + a1=DataArrayInt::New(); + a1->alloc(sz,1); + int *work(a1->getPointer()); + if(sz!=0 && (const DataArrayInt *)_conn) + work=std::copy(_conn->begin(),_conn->end(),a1->getPointer()); + if(sz!=0 && (const DataArrayInt *)_conn_indx) + std::copy(_conn_indx->begin(),_conn_indx->end(),work); + sz=0; + if((const DataArrayDouble *)_coords) + if(_coords->isAllocated()) + sz=_coords->getNbOfElems(); + a2=DataArrayDouble::New(); + a2->alloc(sz,1); + if(sz!=0 && (const DataArrayDouble *)_coords) + std::copy(_coords->begin(),_coords->end(),a2->getPointer()); +} + +void MEDCoupling1DGTUMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings) +{ + INTERP_KERNEL::NormalizedCellType gt((INTERP_KERNEL::NormalizedCellType)tinyInfo[0]); + _cm=&INTERP_KERNEL::CellModel::GetCellModel(gt); + setName(littleStrings[0].c_str()); + setDescription(littleStrings[1].c_str()); + setTimeUnit(littleStrings[2].c_str()); + setTime(tinyInfoD[0],tinyInfo[1],tinyInfo[2]); + int sz0(tinyInfo[3]),sz1(tinyInfo[4]),sz2(tinyInfo[5]),sz3(tinyInfo[6]),sz4(tinyInfo[7]),sz5(tinyInfo[8]); + // + _coords=DataArrayDouble::New(); + std::vector tinyInfo2(tinyInfo.begin()+9,tinyInfo.begin()+9+sz3); + _coords->resizeForUnserialization(tinyInfo2); + std::copy(a2->begin(),a2->end(),_coords->getPointer()); + _conn=DataArrayInt::New(); + std::vector tinyInfo3(tinyInfo.begin()+9+sz3,tinyInfo.begin()+9+sz3+sz4); + _conn->resizeForUnserialization(tinyInfo3); + std::copy(a1->begin(),a1->begin()+_conn->getNbOfElems(),_conn->getPointer()); + _conn_indx=DataArrayInt::New(); + std::vector tinyInfo4(tinyInfo.begin()+9+sz3+sz4,tinyInfo.begin()+9+sz3+sz4+sz5); + _conn_indx->resizeForUnserialization(tinyInfo4); + std::copy(a1->begin()+_conn->getNbOfElems(),a1->end(),_conn_indx->getPointer()); + std::vector littleStrings2(littleStrings.begin()+3,littleStrings.begin()+3+sz0); + _coords->finishUnserialization(tinyInfo2,littleStrings2); + std::vector littleStrings3(littleStrings.begin()+3+sz0,littleStrings.begin()+3+sz0+sz1); + _conn->finishUnserialization(tinyInfo3,littleStrings3); + std::vector littleStrings4(littleStrings.begin()+3+sz0+sz1,littleStrings.begin()+3+sz0+sz1+sz2); + _conn_indx->finishUnserialization(tinyInfo4,littleStrings4); +} + /*! * Finds nodes not used in any cell and returns an array giving a new id to every node * by excluding the unused nodes, for which the array holds -1. The result array is @@ -2054,7 +2775,7 @@ DataArrayInt *MEDCoupling1DGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const int nodeId=conn[conni[0]+j]; if(nodeId==-1) continue; if(nodeId>=0 && nodeId ret(new MEDCoupling1DGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm)); DataArrayInt *nc=0,*nci=0; isShallowCpyOfNodalConnn=retrievePackedNodalConnectivity(nc,nci); MEDCouplingAutoRefCountObjectPtr ncs(nc),ncis(nci); @@ -2419,7 +3140,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesLL(std::vector ret(new MEDCoupling1DGTUMesh(getName(),*_cm)); + MEDCouplingAutoRefCountObjectPtr ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm)); MEDCouplingAutoRefCountObjectPtr tmp1,tmp2; const DataArrayInt *nodalConn(_conn),*nodalConnI(_conn_indx); if(!nodalConn) @@ -2448,6 +3169,76 @@ MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::buildSetInstanceFromThis(int spaceDi return ret.retn(); } +/*! + * This method aggregate the bbox of each cell and put it into bbox parameter. + * + * \return DataArrayDouble * - newly created object (to be managed by the caller) \a this number of cells tuples and 2*spacedim components. + * + * \throw If \a this is not fully set (coordinates and connectivity). + * \throw If a cell in \a this has no valid nodeId. + */ +DataArrayDouble *MEDCoupling1DGTUMesh::getBoundingBoxForBBTree() const +{ + checkFullyDefined(); + int spaceDim(getSpaceDimension()),nbOfCells(getNumberOfCells()),nbOfNodes(getNumberOfNodes()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); ret->alloc(nbOfCells,2*spaceDim); + double *bbox(ret->getPointer()); + for(int i=0;i::max(); + bbox[2*i+1]=-std::numeric_limits::max(); + } + const double *coordsPtr(_coords->getConstPointer()); + const int *conn(_conn->getConstPointer()),*connI(_conn_indx->getConstPointer()); + for(int i=0;i=0 && nodeId MEDCoupling1DGTUMesh::BuildAPolygonFromParts(const std::vector< std::vector >& parts) throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + if(parts.empty()) + return ret; + ret.insert(ret.end(),parts[0].begin(),parts[0].end()); + int ref(ret.back()); + std::size_t sz(parts.size()),nbh(1); + std::vector b(sz,true); b[0]=false; + while(nbh 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().c_str(),*gts.begin())); + ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str()); + 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(); +}