+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
+ int tmp=-1;
+ int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
+ std::vector<bool> fastFinder(sz,false);
+ for(const int *work=begin;work!=end;work++)
+ if(*work>=0 && *work<sz)
+ fastFinder[*work]=true;
+ const int *conn=_conn->begin();
+ int nbNodesPerCell=getNumberOfNodesPerCell();
+ for(int i=0;i<nbOfCells;i++,conn+=nbNodesPerCell)
+ {
+ int ref=0,nbOfHit=0;
+ for(int j=0;j<nbNodesPerCell;j++)
+ if(conn[j]>=0)
+ {
+ ref++;
+ if(fastFinder[conn[j]])
+ nbOfHit++;
+ }
+ if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
+ cellIdsKept->pushBackSilent(i);
+ }
+ cellIdsKeptArr=cellIdsKept.retn();
+}
+
+MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
+{
+ if(other->getType()!=SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED)
+ throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single static geo type each other !");
+ const MEDCoupling1SGTUMesh *otherC=static_cast<const MEDCoupling1SGTUMesh *>(other);
+ return Merge1SGTUMeshes(this,otherC);
+}
+
+MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
+ ret->setCoords(getCoords());
+ const int *nodalConn=_conn->begin();
+ int nbCells=getNumberOfCells();
+ int nbNodesPerCell=getNumberOfNodesPerCell();
+ int geoType=(int)getCellModelEnum();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells*(nbNodesPerCell+1),1);
+ int *cPtr=c->getPointer();
+ for(int i=0;i<nbCells;i++,nodalConn+=nbNodesPerCell)
+ {
+ *cPtr++=geoType;
+ cPtr=std::copy(nodalConn,nodalConn+nbNodesPerCell,cPtr);
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::Range(0,(nbCells+1)*(nbNodesPerCell+1),nbNodesPerCell+1);
+ ret->setConnectivity(c,cI,true);
+ return ret.retn();
+}
+
+DataArrayInt *MEDCoupling1SGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
+{
+ switch(policy)
+ {
+ case 0:
+ return simplexizePol0();
+ case 1:
+ return simplexizePol1();
+ case (int) INTERP_KERNEL::PLANAR_FACE_5:
+ return simplexizePlanarFace5();
+ case (int) INTERP_KERNEL::PLANAR_FACE_6:
+ return simplexizePlanarFace6();
+ default:
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::simplexize : unrecognized policy ! Must be :\n - 0 or 1 (only available for meshdim=2) \n - PLANAR_FACE_5, PLANAR_FACE_6 (only for meshdim=3)");
+ }
+}
+
+/*!
+ * \return DataArrayInt * - the permutation array in "Old to New" mode. For more
+ * info on "Old to New" mode see \ref MEDCouplingArrayRenumbering. The caller
+ * is to delete this array using decrRef() as it is no more needed.
+ */
+DataArrayInt *MEDCoupling1SGTUMesh::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes)
+{
+ DataArrayInt *ret=buildPermArrayForMergeNode(precision,-1,areNodesMerged,newNbOfNodes);
+ if(areNodesMerged)
+ renumberNodes(ret->getConstPointer(),newNbOfNodes);
+ return ret;
+}
+
+/*!
+ * \return DataArrayInt * - the permutation array in "Old to New" mode. For more
+ * info on "Old to New" mode see \ref MEDCouplingArrayRenumbering. The caller
+ * is to delete this array using decrRef() as it is no more needed.
+ */
+DataArrayInt *MEDCoupling1SGTUMesh::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes)
+{
+ DataArrayInt *ret=buildPermArrayForMergeNode(precision,-1,areNodesMerged,newNbOfNodes);
+ if(areNodesMerged)
+ renumberNodes2(ret->getConstPointer(),newNbOfNodes);
+ return ret;
+}
+
+/*!
+ * Removes unused nodes (the node coordinates array is shorten) and returns an array
+ * mapping between new and old node ids in "Old to New" mode. -1 values in the returned
+ * array mean that the corresponding old node is no more used.
+ * \return DataArrayInt * - a new instance of DataArrayInt of length \a
+ * this->getNumberOfNodes() before call of this method. The caller is to
+ * delete this array using decrRef() as it is no more needed.
+ * \throw If the coordinates array is not set.
+ * \throw If the nodal connectivity of cells is not defined.
+ * \throw If the nodal connectivity includes an invalid id.
+ *
+ * \ref cpp_mcumesh_zipCoordsTraducer "Here is a C++ example".<br>
+ * \ref py_mcumesh_zipCoordsTraducer "Here is a Python example".
+ */
+DataArrayInt *MEDCoupling1SGTUMesh::zipCoordsTraducer() throw(INTERP_KERNEL::Exception)
+{
+ int newNbOfNodes=-1;
+ DataArrayInt *traducer=getNodeIdsInUse(newNbOfNodes);
+ renumberNodes(traducer->getConstPointer(),newNbOfNodes);
+ return traducer;
+}
+
+/// @cond INTERNAL
+
+struct MEDCouplingAccVisit
+{
+ MEDCouplingAccVisit():_new_nb_of_nodes(0) { }
+ int operator()(int val) { if(val!=-1) return _new_nb_of_nodes++; else return -1; }
+ int _new_nb_of_nodes;
+};
+
+/// @endcond
+
+/*!
+ * 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
+ * a mapping in "Old to New" mode.
+ * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
+ * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
+ * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
+ * if the node is unused or a new id else. The caller is to delete this
+ * array using decrRef() as it is no more needed.
+ * \throw If the coordinates array is not set.
+ * \throw If the nodal connectivity of cells is not defined.
+ * \throw If the nodal connectivity includes an invalid id.
+ */
+DataArrayInt *MEDCoupling1SGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
+{
+ nbrOfNodesInUse=-1;
+ int nbOfNodes=getNumberOfNodes();
+ int nbOfCells=getNumberOfCells();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ ret->alloc(nbOfNodes,1);
+ int *traducer=ret->getPointer();
+ std::fill(traducer,traducer+nbOfNodes,-1);
+ const int *conn=_conn->begin();
+ int nbNodesPerCell=getNumberOfNodesPerCell();
+ for(int i=0;i<nbOfCells;i++)
+ for(int j=0;j<nbNodesPerCell;j++)
+ if(conn[j]>=0 && conn[j]<nbOfNodes)
+ traducer[conn[j]]=1;
+ else
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << conn[j] << " not in [0," << nbOfNodes << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
+ std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
+ return ret.retn();
+}
+
+/*!
+ * Changes ids of nodes within the nodal connectivity arrays according to a permutation
+ * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
+ * This method is a generalization of shiftNodeNumbersInConn().
+ * \warning This method performs no check of validity of new ids. **Use it with care !**
+ * \param [in] newNodeNumbersO2N - a permutation array, of length \a
+ * this->getNumberOfNodes(), in "Old to New" mode.
+ * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
+ * \throw If the nodal connectivity of cells is not defined.
+ */
+void MEDCoupling1SGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
+{
+ getNumberOfCells();//only to check that all is well defined.
+ _conn->renumberInPlace(newNodeNumbersO2N);
+ updateTime();
+}
+
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<const MEDCoupling1SGTUMesh *> tmp(2);
+ tmp[0]=const_cast<MEDCoupling1SGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1SGTUMesh *>(mesh2);
+ return Merge1SGTUMeshes(tmp);
+}
+
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
+{
+ std::size_t sz=a.size();
+ if(sz==0)
+ return Merge1SGTUMeshesLL(a);
+ for(std::size_t ii=0;ii<sz;ii++)
+ if(!a[ii])
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::Merge1SGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
+ for(std::size_t ii=0;ii<sz;ii++)
+ if(&(a[ii]->getCellModel())!=cm)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : all items must have the same geo type !");
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> > bb(sz);
+ std::vector< const MEDCoupling1SGTUMesh * > aa(sz);
+ int spaceDim=-3;
+ for(std::size_t i=0;i<sz && spaceDim==-3;i++)
+ {
+ const MEDCoupling1SGTUMesh *cur=a[i];
+ const DataArrayDouble *coo=cur->getCoords();
+ if(coo)
+ spaceDim=coo->getNumberOfComponents();
+ }
+ if(spaceDim==-3)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : no spaceDim specified ! unable to perform merge !");
+ for(std::size_t i=0;i<sz;i++)
+ {
+ bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
+ aa[i]=bb[i];
+ }
+ return Merge1SGTUMeshesLL(aa);
+}
+
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
+{
+ if(a.empty())
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : input array must be NON EMPTY !");
+ std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
+ if(!(*it))
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : presence of null instance !");
+ int nbOfCells=(*it)->getNumberOfCells();
+ const DataArrayDouble *coords=(*it)->getCoords();
+ const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
+ int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
+ for(;it!=a.end();it++)
+ {
+ if(cm!=&((*it)->getCellModel()))
+ throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
+ nbOfCells+=(*it)->getNumberOfCells();
+ if(coords!=(*it)->getCoords())
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : not lying on same coords !");
+ }
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
+ ret->setCoords(coords);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New();
+ c->alloc(nbOfCells*nbNodesPerCell,1);
+ int *cPtr=c->getPointer();
+ int offset=0;
+ for(it=a.begin();it!=a.end();it++)
+ {
+ int curConnLgth=(*it)->getNodalConnectivityLength();
+ const int *curC=(*it)->_conn->begin();
+ cPtr=std::copy(curC,curC+curConnLgth,cPtr);
+ }
+ //
+ ret->_conn=c;
+ return ret.retn();
+}
+
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
+{
+ if(a.empty())
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : input array must be NON EMPTY !");
+ std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
+ int nbOfCells=(*it)->getNumberOfCells();
+ const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
+ int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
+ for(;it!=a.end();it++)
+ {
+ if(cm!=&((*it)->getCellModel()))
+ throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
+ nbOfCells+=(*it)->getNumberOfCells();
+ }
+ std::vector<const MEDCouplingPointSet *> aps(a.size());
+ std::copy(a.begin(),a.end(),aps.begin());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
+ ret->setCoords(pts);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New();
+ c->alloc(nbOfCells*nbNodesPerCell,1);
+ int *cPtr=c->getPointer();
+ int offset=0;
+ for(it=a.begin();it!=a.end();it++)
+ {
+ int curConnLgth=(*it)->getNodalConnectivityLength();
+ const int *curC=(*it)->_conn->begin();
+ cPtr=std::transform(curC,curC+curConnLgth,cPtr,std::bind2nd(std::plus<int>(),offset));
+ offset+=(*it)->getNumberOfNodes();
+ }
+ //
+ ret->_conn=c;
+ return ret.retn();
+}
+
+MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
+{
+ int ncell=getNumberOfCells();
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+ ret->setCoords(_coords);
+ std::size_t nbOfElemsRet=std::distance(begin,end);
+ const int *inConn=_conn->getConstPointer();
+ int sz=getNumberOfNodesPerCell();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
+ int *connPtr=connRet->getPointer();
+ for(const int *work=begin;work!=end;work++,connPtr+=sz)
+ {
+ if(*work>=0 && *work<ncell)
+ std::copy(inConn+(work[0])*sz,inConn+(work[0]+1)*sz,connPtr);
+ else
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ ret->_conn=connRet;
+ ret->copyTinyInfoFrom(this);
+ return ret.retn();
+}
+
+MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
+{
+ int ncell=getNumberOfCells();
+ int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : ");
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+ ret->setCoords(_coords);
+ const int *inConn=_conn->getConstPointer();
+ int sz=getNumberOfNodesPerCell();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
+ int *connPtr=connRet->getPointer();
+ int curId=start;
+ for(int i=0;i<nbOfElemsRet;i++,connPtr+=sz,curId+=step)
+ {
+ if(curId>=0 && curId<ncell)
+ std::copy(inConn+curId*sz,inConn+(curId+1)*sz,connPtr);
+ else
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : On pos #" << i << " input cell id =" << curId << " should be in [0," << ncell << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ ret->_conn=connRet;
+ ret->copyTinyInfoFrom(this);
+ return ret.retn();
+}
+
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1;
+ const DataArrayInt *nodalConn(_conn);
+ if(!nodalConn)
+ {
+ tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
+ }
+ else
+ {
+ tmp1=_conn;
+ tmp1->incrRef();
+ }
+ ret->_conn=tmp1;
+ if(!_coords)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
+ ret->setCoords(coords);
+ }
+ else
+ ret->setCoords(_coords);
+ return ret.retn();
+}
+
+DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol0() throw(INTERP_KERNEL::Exception)
+{
+ int nbOfCells=getNumberOfCells();
+ if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
+ return DataArrayInt::Range(0,nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
+ const int *c(_conn->begin());
+ int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
+ for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
+ {
+ newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[2];
+ newConnPtr[3]=c[0]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
+ retPtr[0]=i; retPtr[1]=i;
+ }
+ _conn=newConn;
+ _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
+ updateTime();
+ return ret.retn();
+}
+
+DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol1() throw(INTERP_KERNEL::Exception)
+{
+ int nbOfCells=getNumberOfCells();
+ if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
+ return DataArrayInt::Range(0,nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
+ const int *c(_conn->begin());
+ int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
+ for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
+ {
+ newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[3];
+ newConnPtr[3]=c[1]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
+ retPtr[0]=i; retPtr[1]=i;
+ }
+ _conn=newConn;
+ _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
+ updateTime();
+ return ret.retn();
+}
+
+DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace5() throw(INTERP_KERNEL::Exception)
+{
+ int nbOfCells=getNumberOfCells();
+ if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
+ return DataArrayInt::Range(0,nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(5*4*nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(5*nbOfCells,1);
+ const int *c(_conn->begin());
+ int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
+ for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=20,retPtr+=5)
+ {
+ for(int j=0;j<20;j++)
+ newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_5_WO[j]];
+ retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i;
+ }
+ _conn=newConn;
+ _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
+ updateTime();
+ return ret.retn();
+}
+
+DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace6() throw(INTERP_KERNEL::Exception)
+{
+ int nbOfCells=getNumberOfCells();
+ if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
+ return DataArrayInt::Range(0,nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(6*4*nbOfCells,1);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(6*nbOfCells,1);
+ const int *c(_conn->begin());
+ int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
+ for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=20,retPtr+=6)
+ {
+ for(int j=0;j<24;j++)
+ newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_6_WO[j]];
+ retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i; retPtr[5]=i;
+ }
+ _conn=newConn;
+ _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
+ updateTime();
+ return ret.retn();
+}
+
+void MEDCoupling1SGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
+{
+ stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Name : \"" << getName() << "\".";
+ stream << " Mesh dimension : " << getMeshDimension() << ".";
+ if(!_coords)
+ { stream << " No coordinates set !"; return ; }
+ if(!_coords->isAllocated())
+ { stream << " Coordinates set but not allocated !"; return ; }
+ stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
+ stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
+ if(!(const DataArrayInt *)_conn)
+ { stream << std::endl << "Nodal connectivity NOT set !"; return ; }
+ if(_conn->isAllocated())
+ {
+ if(_conn->getNumberOfComponents()==1)
+ stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
+ }
+}
+
+void MEDCoupling1SGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
+{
+ if(!((const DataArrayInt *)_conn) || !((const DataArrayDouble *)_coords))
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFullyDefined : part of this is not fully defined.");
+}
+
+/*!
+ * First step of unserialization process.
+ */
+bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
+{
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !");
+}
+
+/*!
+ * 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
+ * (1) meshes contain the same number of nodes and the same number of elements of the
+ * same types (2) three cells of the two meshes (first, last and middle) are based
+ * on coincident nodes (with a specified precision).
+ * \param [in] other - the mesh to compare with.
+ * \param [in] prec - the precision used to compare nodes of the two meshes.
+ * \throw If the two meshes do not match.
+ */
+void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingPointSet::checkFastEquivalWith(other,prec);
+ const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !");
+}
+
+MEDCouplingPointSet *MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
+{
+ if(!other)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
+ const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
+ if(!otherC)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
+ std::vector<const MEDCoupling1SGTUMesh *> ms(2);
+ ms[0]=this;
+ ms[1]=otherC;
+ return Merge1SGTUMeshesOnSameCoords(ms);
+}
+
+void MEDCoupling1SGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
+{
+ checkFullyDefined();
+ int nbOfNodes=getNumberOfNodes();
+ int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
+ revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
+ std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
+ const int *conn=_conn->begin();
+ int nbOfCells=getNumberOfCells();
+ int nbOfEltsInRevNodal=0;
+ int nbOfNodesPerCell=getNumberOfNodesPerCell();
+ for(int eltId=0;eltId<nbOfCells;eltId++)
+ {
+ for(int j=0;j<nbOfNodesPerCell;j++,conn++)
+ {
+ if(conn[0]>=0 && conn[0]<nbOfNodes)
+ {
+ nbOfEltsInRevNodal++;
+ revNodalIndxPtr[conn[0]+1]++;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
+ conn=_conn->begin();
+ int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
+ revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
+ std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
+ for(int eltId=0;eltId<nbOfCells;eltId++)
+ {
+ for(int j=0;j<nbOfNodesPerCell;j++,conn++)
+ {
+ *std::find_if(revNodalPtr+revNodalIndxPtr[*conn],revNodalPtr+revNodalIndxPtr[*conn+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
+ }
+ }
+}
+
+/*!
+ * Use \a nodalConn array as nodal connectivity of \a this. The input \a nodalConn pointer can be null.
+ * This method tests, if the input \a nodalConn is not null, that :
+ * - it has one component.
+ * - the number of tuples compatible with the number of node per cell.
+ */
+void MEDCoupling1SGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception)
+{
+ if(!nodalConn)
+ {
+ _conn=nodalConn;
+ return;
+ }
+ const DataArrayInt *c1(nodalConn);
+ if(c1->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::setNodalConnectivity : input nodal connectivity array set must have exactly one component !");
+ if(!c1->isAllocated())
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::setNodalConnectivity : input nodal connectivity array must be allocated !");
+ int nbTuples=c1->getNumberOfTuples();
+ if(nbTuples%getNumberOfNodesPerCell()!=0)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::setNodalConnectivity : input nodal connectivity number of tuples is incompatible with geometric type !");
+ nodalConn->incrRef();
+ _conn=nodalConn;
+ declareAsNew();
+}
+
+/*!
+ * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
+ */
+DataArrayInt *MEDCoupling1SGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
+{
+ const DataArrayInt *ret(_conn);
+ return const_cast<DataArrayInt *>(ret);
+}
+
+/*!
+ * Allocates memory to store an estimation of the given number of cells. Closer is the estimation to the number of cells effectively inserted,
+ * less will be the needs to realloc. If the number of cells to be inserted is not known simply put 0 to this parameter.
+ * If a nodal connectivity previouly existed before the call of this method, it will be reset.
+ *
+ * \param [in] nbOfCells - estimation of the number of cell \a this mesh will contain.
+ */
+void MEDCoupling1SGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
+{
+ if(nbOfCells<0)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::allocateCells : the input number of cells should be >= 0 !");
+ _conn=DataArrayInt::New();
+ _conn->reserve(getNumberOfNodesPerCell()*nbOfCells);
+ declareAsNew();
+}
+
+/*!
+ * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
+ *
+ * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
+ * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
+ * \throw If the length of the input nodal connectivity array of the cell to add is not equal to number of nodes per cell relative to the unique geometric type
+ * attached to \a this.
+ * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
+ */
+void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
+{
+ int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
+ int ref=getNumberOfNodesPerCell();
+ if(sz==ref)
+ {
+ DataArrayInt *c(_conn);
+ if(c)
+ c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
+ else
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1SGTUMesh::allocateCells before !");
+ }
+ else
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::insertNextCell : input nodal size (" << sz << ") does not match number of nodes per cell of this (";
+ oss << ref << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }