From: ageay Date: Wed, 11 Mar 2009 17:25:45 +0000 (+0000) Subject: Some new functionalities. X-Git-Tag: V5_1_main_FINAL~421 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c6c0d0c51154611fd6cfd6920cac2350adced3a;p=tools%2Fmedcoupling.git Some new functionalities. --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 2139675a7..f36430f33 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -47,3 +47,14 @@ MEDCouplingField::~MEDCouplingField() if(_mesh) _mesh->decrRef(); } + +MEDCouplingField::MEDCouplingField(const MEDCouplingField& other):_name(other._name),_desc(other._name), + _time(other._time),_dt(other._dt),_it(other._it), + _mesh(0),_type(other._type) +{ + if(other._mesh) + { + _mesh=other._mesh; + _mesh->incrRef(); + } +} diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index c8e880a77..30dd61a66 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -32,12 +32,12 @@ namespace ParaMEDMEM { public: virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; - void setMesh(MEDCouplingMesh *mesh); + void setMesh(ParaMEDMEM::MEDCouplingMesh *mesh); void setTime(double val) { _time=val; } double getTime() const { return _time; } void setDtIt(int dt, int it) { _dt=dt; _it=it; } void getDtIt(int& dt, int& it) { dt=_dt; it=_it; } - MEDCouplingMesh *getMesh() const { return _mesh; } + ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _mesh; } void setName(const char *name) { _name=name; } void setDescription(const char *desc) { _desc=desc; } const char *getName() const { return _name.c_str(); } @@ -46,6 +46,7 @@ namespace ParaMEDMEM void updateTime(); protected: MEDCouplingField(TypeOfField type):_time(0.),_dt(-1),_it(-1),_mesh(0),_type(type) { } + MEDCouplingField(const MEDCouplingField& other); virtual ~MEDCouplingField(); protected: std::string _name; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index b13a9ec1e..77a0ffad6 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -28,10 +28,21 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(TypeOfField type) return new MEDCouplingFieldDouble(type); } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const +{ + return new MEDCouplingFieldDouble(*this,recDeepCpy); +} + MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type):MEDCouplingField(type),_array(0) { } +MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingField(other),_array(0) +{ + if(other._array) + _array=other._array->performCpy(deepCpy); +} + MEDCouplingFieldDouble::~MEDCouplingFieldDouble() { if(_array) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 82de9c3bd..fea2d2222 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -28,6 +28,7 @@ namespace ParaMEDMEM { public: static MEDCouplingFieldDouble *New(TypeOfField type); + MEDCouplingFieldDouble *clone(bool recDeepCpy) const; void checkCoherency() const throw(INTERP_KERNEL::Exception); double getIJ(int tupleId, int compoId) const { return _array->getIJ(tupleId,compoId); } void setArray(DataArrayDouble *array); @@ -39,6 +40,7 @@ namespace ParaMEDMEM void updateTime(); private: MEDCouplingFieldDouble(TypeOfField type); + MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy); ~MEDCouplingFieldDouble(); private: DataArrayDouble *_array; diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 78c1913a9..41527486b 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -29,6 +29,7 @@ namespace ParaMEDMEM public: void setName(const char *name) { _name=name; } const char *getName() const { return _name.c_str(); } + virtual bool isEqual(const MEDCouplingMesh *other, double prec) const { return _name==other->_name; } virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; virtual bool isStructured() const = 0; virtual int getNumberOfCells() const = 0; @@ -36,6 +37,8 @@ namespace ParaMEDMEM virtual int getSpaceDimension() const = 0; virtual int getMeshDimension() const = 0; protected: + MEDCouplingMesh() { } + MEDCouplingMesh(const MEDCouplingMesh& other):_name(other._name) { } virtual ~MEDCouplingMesh() { } private: std::string _name; diff --git a/src/MEDCoupling/MEDCouplingSMesh.cxx b/src/MEDCoupling/MEDCouplingSMesh.cxx index 724b157dd..4eb480736 100644 --- a/src/MEDCoupling/MEDCouplingSMesh.cxx +++ b/src/MEDCoupling/MEDCouplingSMesh.cxx @@ -50,6 +50,14 @@ void MEDCouplingSMesh::updateTime() updateTimeWith(*_z_array); } +bool MEDCouplingSMesh::isEqual(const MEDCouplingMesh *other, double prec) const +{ + const MEDCouplingSMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + return true; +} + void MEDCouplingSMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { const char msg0[]="Invalid "; diff --git a/src/MEDCoupling/MEDCouplingSMesh.hxx b/src/MEDCoupling/MEDCouplingSMesh.hxx index d782107db..fb170beda 100644 --- a/src/MEDCoupling/MEDCouplingSMesh.hxx +++ b/src/MEDCoupling/MEDCouplingSMesh.hxx @@ -30,6 +30,7 @@ namespace ParaMEDMEM public: static MEDCouplingSMesh *New(); void updateTime(); + bool isEqual(const MEDCouplingMesh *other, double prec) const; void checkCoherency() const throw(INTERP_KERNEL::Exception); bool isStructured() const; int getNumberOfCells() const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 379f326ae..9c6b4fdb1 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -23,25 +23,32 @@ using namespace ParaMEDMEM; +const char MEDCouplingUMesh::PART_OF_NAME[]="PartOf_"; + MEDCouplingUMesh *MEDCouplingUMesh::New() { - return new MEDCouplingUMesh; + return new MEDCouplingUMesh; +} + +MEDCouplingUMesh *MEDCouplingUMesh::clone(bool recDeepCpy) const +{ + return new MEDCouplingUMesh(*this,recDeepCpy); } void MEDCouplingUMesh::updateTime() { - if(_nodal_connec) - { - updateTimeWith(*_nodal_connec); - } - if(_nodal_connec_index) - { - updateTimeWith(*_nodal_connec_index); - } - if(_coords) - { - updateTimeWith(*_coords); - } + if(_nodal_connec) + { + updateTimeWith(*_nodal_connec); + } + if(_nodal_connec_index) + { + updateTimeWith(*_nodal_connec_index); + } + if(_coords) + { + updateTimeWith(*_coords); + } } MEDCouplingUMesh::MEDCouplingUMesh():_iterator(-1),_mesh_dim(-1), @@ -51,97 +58,219 @@ MEDCouplingUMesh::MEDCouplingUMesh():_iterator(-1),_mesh_dim(-1), void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { - for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) - { - if(INTERP_KERNEL::CellModel::getCellModel(*iter).getDimension()!=_mesh_dim) + for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) { - std::ostringstream message; - message << "Mesh invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter); - throw INTERP_KERNEL::Exception(message.str().c_str()); + if(INTERP_KERNEL::CellModel::getCellModel(*iter).getDimension()!=_mesh_dim) + { + std::ostringstream message; + message << "Mesh invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter); + throw INTERP_KERNEL::Exception(message.str().c_str()); + } } - } } void MEDCouplingUMesh::setMeshDimension(unsigned meshDim) { - _mesh_dim=meshDim; - declareAsNew(); + _mesh_dim=meshDim; + declareAsNew(); } void MEDCouplingUMesh::allocateCells(int nbOfCells) { - if(_nodal_connec_index) - { - _nodal_connec_index->decrRef(); - } - if(_nodal_connec) - { - _nodal_connec->decrRef(); - } - - _nodal_connec_index=DataArrayInt::New(); - _nodal_connec_index->alloc(nbOfCells+1,1); - int *pt=_nodal_connec_index->getPointer(); - pt[0]=0; - _nodal_connec=DataArrayInt::New(); - _nodal_connec->alloc(2*nbOfCells,1); - _iterator=0; - _types.clear(); - declareAsNew(); + if(_nodal_connec_index) + { + _nodal_connec_index->decrRef(); + } + if(_nodal_connec) + { + _nodal_connec->decrRef(); + } + + _nodal_connec_index=DataArrayInt::New(); + _nodal_connec_index->alloc(nbOfCells+1,1); + int *pt=_nodal_connec_index->getPointer(); + pt[0]=0; + _nodal_connec=DataArrayInt::New(); + _nodal_connec->alloc(2*nbOfCells,1); + _iterator=0; + _types.clear(); + declareAsNew(); } void MEDCouplingUMesh::setCoords(DataArrayDouble *coords) { - if( coords != _coords ) - { - if (_coords) - _coords->decrRef(); + if( coords != _coords ) + { + if (_coords) + _coords->decrRef(); _coords=coords; if(_coords) - _coords->incrRef(); + _coords->incrRef(); declareAsNew(); } } void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) { - int *pt=_nodal_connec_index->getPointer(); - int idx=pt[_iterator]; + int *pt=_nodal_connec_index->getPointer(); + int idx=pt[_iterator]; - _nodal_connec->writeOnPlace(idx,type,nodalConnOfCell,size); - _types.insert(type); - pt[++_iterator]=idx+size+1; + _nodal_connec->writeOnPlace(idx,type,nodalConnOfCell,size); + _types.insert(type); + pt[++_iterator]=idx+size+1; } void MEDCouplingUMesh::finishInsertingCells() { - int *pt=_nodal_connec_index->getPointer(); - int idx=pt[_iterator]; + int *pt=_nodal_connec_index->getPointer(); + int idx=pt[_iterator]; - _nodal_connec->reAlloc(idx); - _nodal_connec_index->reAlloc(_iterator+1); - _iterator=-1; + _nodal_connec->reAlloc(idx); + _nodal_connec_index->reAlloc(_iterator+1); + _iterator=-1; +} + +bool MEDCouplingUMesh::isEqual(const MEDCouplingMesh *other, double prec) const +{ + checkFullyDefined(); + const MEDCouplingUMesh *otherC=dynamic_cast(other); + if(!otherC) + return false; + otherC->checkFullyDefined(); + if(!MEDCouplingMesh::isEqual(other,prec)) + return false; + if(_mesh_dim!=otherC->_mesh_dim) + return false; + if(_types!=otherC->_types) + return false; + if(!_coords->isEqual(otherC->_coords,prec)) + return false; + return true; +} + +/*! + * \b WARNING this method do the assumption that connectivity lies on the coordinates set. + * For speed reasons no check of this will be done. + */ +void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const +{ + checkFullyDefined(); + int nbOfNodes=getNumberOfNodes(); + int *revNodalIndxPtr=new int[nbOfNodes+1]; + revNodalIndx->useArray(revNodalIndxPtr,true,CPP_DEALLOC,nbOfNodes+1,1); + std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0); + const int *conn=_nodal_connec->getPointer(); + const int *connIndex=_nodal_connec_index->getPointer(); + int nbOfCells=getNumberOfCells(); + int nbOfEltsInRevNodal=0; + for(int eltId=0;eltId=0)//for polyhedrons + { + nbOfEltsInRevNodal++; + revNodalIndxPtr[(*iter)+1]++; + } + } + std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus()); + int *revNodalPtr=new int[nbOfEltsInRevNodal]; + revNodal->useArray(revNodalPtr,true,CPP_DEALLOC,nbOfEltsInRevNodal,1); + std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1); + for(int eltId=0;eltId=0)//for polyhedrons + *std::find_if(revNodalPtr+revNodalIndxPtr[*iter],revNodalPtr+revNodalIndxPtr[*iter+1],std::bind2nd(std::equal_to(),-1))=eltId; + } +} + +void MEDCouplingUMesh::zipCoords() +{ + checkFullyDefined(); + DataArrayInt *traducer=zipCoordsTraducer(); + traducer->decrRef(); +} + +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; +}; + +/*! + * Array returned is the correspondance old to new. + * The maximum value stored in returned array is the number of nodes of 'this' minus 1 after call of this method. + * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes. + * -1 values in returned array means that the corresponding old node is no more used. + */ +DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() +{ + DataArrayInt *ret=DataArrayInt::New(); + int nbOfNodes=getNumberOfNodes(); + int spaceDim=getSpaceDimension(); + int *traducer=new int[nbOfNodes]; + std::fill(traducer,traducer+nbOfNodes,-1); + ret->useArray(traducer,true,CPP_DEALLOC,nbOfNodes,1); + int nbOfCells=getNumberOfCells(); + const int *connIndex=_nodal_connec_index->getPointer(); + int *conn=_nodal_connec->getPointer(); + for(int i=0;i=0) + traducer[conn[j]]=1; + int newNbOfNodes=std::count(traducer,traducer+nbOfNodes,1); + std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit()); + for(int i=0;i=0) + conn[j]=traducer[conn[j]]; + DataArrayDouble *newCoords=DataArrayDouble::New(); + double *newCoordsPtr=new double[newNbOfNodes*spaceDim]; + const double *oldCoordsPtr=_coords->getPointer(); + newCoords->useArray(newCoordsPtr,true,CPP_DEALLOC,newNbOfNodes,spaceDim); + int *work=std::find_if(traducer,traducer+nbOfNodes,std::bind2nd(std::not_equal_to(),-1)); + for(;work!=traducer+nbOfNodes;work=std::find_if(work,traducer+nbOfNodes,std::bind2nd(std::not_equal_to(),-1))) + { + newCoordsPtr=std::copy(oldCoordsPtr+spaceDim*(work-traducer),oldCoordsPtr+spaceDim*(work-traducer+1),newCoordsPtr); + work++; + } + setCoords(newCoords); + newCoords->decrRef(); + return ret; +} + +MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const +{ + MEDCouplingUMesh *ret=buildPartOfMySelfKeepCoords(start,end); + if(!keepCoords) + ret->zipCoords(); + return ret; } INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::getTypeOfCell(int cellId) const { - int *ptI=_nodal_connec_index->getPointer(); - int *pt=_nodal_connec->getPointer(); - return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]]; + int *ptI=_nodal_connec_index->getPointer(); + int *pt=_nodal_connec->getPointer(); + return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]]; } int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const { - int *ptI=_nodal_connec_index->getPointer(); - return ptI[cellId+1]-ptI[cellId]-1; + int *ptI=_nodal_connec_index->getPointer(); + return ptI[cellId+1]-ptI[cellId]-1; } void MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes) { - if(_nodal_connec!=conn) - { - if(_nodal_connec) - _nodal_connec->decrRef(); + if(_nodal_connec!=conn) + { + if(_nodal_connec) + _nodal_connec->decrRef(); _nodal_connec=conn; if(_nodal_connec) _nodal_connec->incrRef(); @@ -158,14 +287,26 @@ void MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connInd computeTypes(); } +MEDCouplingUMesh::MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy):MEDCouplingMesh(other),_iterator(-1),_mesh_dim(other._mesh_dim), + _nodal_connec(0),_nodal_connec_index(0),_coords(0), + _types(other._types) +{ + if(other._nodal_connec) + _nodal_connec=other._nodal_connec->performCpy(deepCpy); + if(other._nodal_connec_index) + _nodal_connec_index=other._nodal_connec_index->performCpy(deepCpy); + if(other._coords) + _coords=other._coords->performCpy(deepCpy); +} + MEDCouplingUMesh::~MEDCouplingUMesh() { - if(_nodal_connec) - _nodal_connec->decrRef(); - if(_nodal_connec_index) - _nodal_connec_index->decrRef(); - if(_coords) - _coords->decrRef(); + if(_nodal_connec) + _nodal_connec->decrRef(); + if(_nodal_connec_index) + _nodal_connec_index->decrRef(); + if(_coords) + _coords->decrRef(); } void MEDCouplingUMesh::computeTypes() @@ -181,6 +322,15 @@ void MEDCouplingUMesh::computeTypes() } } +/*! + * This method checks that all arrays are set. If yes nothing done if no an exception is thrown. + */ +void MEDCouplingUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception) +{ + if(!_nodal_connec_index || !_nodal_connec || !_coords) + throw INTERP_KERNEL::Exception("Reverse nodal connectivity computation requires full connectivity and coordinates set in unstructured mesh."); +} + bool MEDCouplingUMesh::isStructured() const { return false; @@ -188,32 +338,68 @@ bool MEDCouplingUMesh::isStructured() const int MEDCouplingUMesh::getNumberOfCells() const { - if(_nodal_connec_index) - if(_iterator==-1) - return _nodal_connec_index->getNumberOfTuples()-1; - else - return _iterator; - else - throw INTERP_KERNEL::Exception("Unable to get number of cells because no coordinates specified !"); + if(_nodal_connec_index) + if(_iterator==-1) + return _nodal_connec_index->getNumberOfTuples()-1; + else + return _iterator; + else + throw INTERP_KERNEL::Exception("Unable to get number of cells because no coordinates specified !"); } int MEDCouplingUMesh::getNumberOfNodes() const { - if(_coords) - return _coords->getNumberOfTuples(); - else - throw INTERP_KERNEL::Exception("Unable to get number of nodes because no coordinates specified !"); + if(_coords) + return _coords->getNumberOfTuples(); + else + throw INTERP_KERNEL::Exception("Unable to get number of nodes because no coordinates specified !"); } int MEDCouplingUMesh::getSpaceDimension() const { - if(_coords) - return _coords->getNumberOfComponents(); - else - throw INTERP_KERNEL::Exception("Unable to get space dimension because no coordinates specified !"); + if(_coords) + return _coords->getNumberOfComponents(); + else + throw INTERP_KERNEL::Exception("Unable to get space dimension because no coordinates specified !"); } int MEDCouplingUMesh::getMeshLength() const { return _nodal_connec->getNbOfElems(); } + +MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *start, const int *end) const +{ + checkFullyDefined(); + MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); + std::ostringstream stream; stream << PART_OF_NAME << getName(); + ret->setName(stream.str().c_str()); + ret->_mesh_dim=_mesh_dim; + ret->setCoords(_coords); + int nbOfElemsRet=end-start; + int *connIndexRet=new int[nbOfElemsRet+1]; + connIndexRet[0]=0; + const int *conn=_nodal_connec->getPointer(); + const int *connIndex=_nodal_connec_index->getPointer(); + int newNbring=0; + for(const int *work=start;work!=end;work++,newNbring++) + connIndexRet[newNbring+1]=connIndexRet[newNbring]+connIndex[*work+1]-connIndex[*work]; + int *connRet=new int[connIndexRet[nbOfElemsRet]]; + int *connRetWork=connRet; + std::set types; + for(const int *work=start;work!=end;work++) + { + types.insert((INTERP_KERNEL::NormalizedCellType)conn[connIndex[*work]]); + connRetWork=std::copy(conn+connIndex[*work],conn+connIndex[*work+1],connRetWork); + } + DataArrayInt *connRetArr=DataArrayInt::New(); + connRetArr->useArray(connRet,true,CPP_DEALLOC,connIndexRet[nbOfElemsRet],1); + DataArrayInt *connIndexRetArr=DataArrayInt::New(); + connIndexRetArr->useArray(connIndexRet,true,CPP_DEALLOC,nbOfElemsRet+1,1); + ret->setConnectivity(connRetArr,connIndexRetArr,false); + ret->_types=types; + connRetArr->decrRef(); + connIndexRetArr->decrRef(); + return ret; +} + diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 4fbbf3df5..a0bf6419b 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -30,7 +30,9 @@ namespace ParaMEDMEM { public: static MEDCouplingUMesh *New(); + MEDCouplingUMesh *clone(bool recDeepCpy) const; void updateTime(); + bool isEqual(const MEDCouplingMesh *other, double prec) const; void checkCoherency() const throw(INTERP_KERNEL::Exception); void setMeshDimension(unsigned meshDim); void allocateCells(int nbOfCells); @@ -38,7 +40,7 @@ namespace ParaMEDMEM DataArrayDouble *getCoords() const { return _coords; } void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell); void finishInsertingCells(); - const std::set getAllTypes() const { return _types; } + const std::set& getAllTypes() const { return _types; } void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); DataArrayInt *getNodalConnectivity() const { return _nodal_connec; } DataArrayInt *getNodalConnectivityIndex() const { return _nodal_connec_index; } @@ -50,10 +52,19 @@ namespace ParaMEDMEM int getSpaceDimension() const; int getMeshDimension() const { return _mesh_dim; } int getMeshLength() const; + //tools + void zipCoords(); + DataArrayInt *zipCoordsTraducer(); + void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const; + MEDCouplingUMesh *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const; private: MEDCouplingUMesh(); + MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy); ~MEDCouplingUMesh(); void computeTypes(); + void checkFullyDefined() const throw(INTERP_KERNEL::Exception); + //tools + MEDCouplingUMesh *buildPartOfMySelfKeepCoords(const int *start, const int *end) const; private: //! this iterator stores current position in _nodal_connec array. mutable int _iterator; @@ -62,6 +73,8 @@ namespace ParaMEDMEM DataArrayInt *_nodal_connec_index; DataArrayDouble *_coords; std::set _types; + private: + static const char PART_OF_NAME[]; }; } diff --git a/src/MEDCoupling/MemArray.cxx b/src/MEDCoupling/MemArray.cxx index 90d43a8fe..d6741d1ab 100644 --- a/src/MEDCoupling/MemArray.cxx +++ b/src/MEDCoupling/MemArray.cxx @@ -30,6 +30,22 @@ DataArrayDouble *DataArrayDouble::New() return new DataArrayDouble; } +DataArrayDouble *DataArrayDouble::deepCopy() const +{ + return new DataArrayDouble(*this); +} + +DataArrayDouble *DataArrayDouble::performCpy(bool deepCpy) const +{ + if(deepCpy) + return deepCopy(); + else + { + incrRef(); + return const_cast(this); + } +} + void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) { _nb_of_tuples=nbOfTuple; @@ -38,6 +54,11 @@ void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) declareAsNew(); } +bool DataArrayDouble::isEqual(DataArrayDouble *other, double prec) const +{ + return true; +} + void DataArrayDouble::reAlloc(int nbOfTuples) { _mem.reAlloc(_info_on_compo.size()*nbOfTuples); @@ -58,6 +79,22 @@ DataArrayInt *DataArrayInt::New() return new DataArrayInt; } +DataArrayInt *DataArrayInt::deepCopy() const +{ + return new DataArrayInt(*this); +} + +DataArrayInt *DataArrayInt::performCpy(bool deepCpy) const +{ + if(deepCpy) + return deepCopy(); + else + { + incrRef(); + return const_cast(this); + } +} + void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) { _nb_of_tuples=nbOfTuple; diff --git a/src/MEDCoupling/MemArray.hxx b/src/MEDCoupling/MemArray.hxx index b8c9c4e38..06c0a6d25 100644 --- a/src/MEDCoupling/MemArray.hxx +++ b/src/MEDCoupling/MemArray.hxx @@ -31,6 +31,7 @@ namespace ParaMEDMEM { public: MemArray():_nb_of_elem(-1),_ownership(false),_pointer(0),_dealloc(CPP_DEALLOC) { } + MemArray(const MemArray& other); T *getPointer() const { return _pointer; } MemArray &operator=(const MemArray& other); T operator[](int id) const { return _pointer[id]; } @@ -77,7 +78,10 @@ namespace ParaMEDMEM { public: static DataArrayDouble *New(); + DataArrayDouble *deepCopy() const; + DataArrayDouble *performCpy(bool deepCpy) const; void alloc(int nbOfTuple, int nbOfCompo); + bool isEqual(DataArrayDouble *other, double prec) const; //!alloc or useArray should have been called before. void reAlloc(int nbOfTuples); double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } @@ -97,10 +101,13 @@ namespace ParaMEDMEM { public: static DataArrayInt *New(); + DataArrayInt *deepCopy() const; + DataArrayInt *performCpy(bool deepCpy) const; void alloc(int nbOfTuple, int nbOfCompo); //!alloc or useArray should have been called before. void reAlloc(int nbOfTuples); int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } + void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } int *getPointer() const { return _mem.getPointer(); } void useArray(int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } diff --git a/src/MEDCoupling/MemArray.txx b/src/MEDCoupling/MemArray.txx index c0b06e8e5..92076ca90 100644 --- a/src/MEDCoupling/MemArray.txx +++ b/src/MEDCoupling/MemArray.txx @@ -25,10 +25,20 @@ #include #include -#include namespace ParaMEDMEM { + template + MemArray::MemArray(const MemArray& other):_nb_of_elem(-1),_ownership(false),_pointer(0),_dealloc(CPP_DEALLOC) + { + if(other._pointer) + { + T *pointer=new T[other._nb_of_elem]; + std::copy(other._pointer,other._pointer+other._nb_of_elem,pointer); + useArray(pointer,true,CPP_DEALLOC,other._nb_of_elem); + } + } + template void MemArray::useArray(void *array, bool ownership, DeallocType type, int nbOfElem) { diff --git a/src/MEDCoupling/RefCountObject.hxx b/src/MEDCoupling/RefCountObject.hxx index ca28fd1bf..3afc8b98c 100644 --- a/src/MEDCoupling/RefCountObject.hxx +++ b/src/MEDCoupling/RefCountObject.hxx @@ -37,14 +37,16 @@ namespace ParaMEDMEM class RefCountObject : public TimeLabel { - public: + protected: RefCountObject():_cnt(1) { } + RefCountObject(const RefCountObject& other):_cnt(1) { } + public: bool decrRef() { bool ret=((--_cnt)==0); if(ret)delete this; return ret; } - void incrRef() { _cnt++; } + void incrRef() const { _cnt++; } protected: virtual ~RefCountObject() { } private: - int _cnt; + mutable int _cnt; }; }