From: Anthony Geay Date: Tue, 1 Dec 2015 17:07:38 +0000 (+0100) Subject: step 4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=019af0a08744917b7cf7abf4a6a470aed09fe3ed;p=tools%2Fmedcoupling.git step 4 --- diff --git a/src/MEDLoader/MEDFileEquivalence.cxx b/src/MEDLoader/MEDFileEquivalence.cxx index ae556d85b..5f9ff6de4 100644 --- a/src/MEDLoader/MEDFileEquivalence.cxx +++ b/src/MEDLoader/MEDFileEquivalence.cxx @@ -69,6 +69,73 @@ MEDFileMesh *MEDFileEquivalencePair::getMesh() return getFather()->getMesh(); } +MEDFileEquivalencePair *MEDFileEquivalencePair::deepCpy(MEDFileEquivalences *father) const +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileEquivalencePair(father,_name,_description)); + const MEDFileEquivalenceCell *cell(_cell); + if(cell) + ret->_cell=cell->deepCpy(const_cast(this)); + const MEDFileEquivalenceNode *node(_node); + if(node) + ret->_node=node->deepCpy(const_cast(this)); + return ret.retn(); +} + +bool MEDFileEquivalencePair::isEqual(const MEDFileEquivalencePair *other, std::string& what) const +{ + if(_name!=other->_name) + { + std::ostringstream oss; oss << "Names differs : " << _name << " != " << other->_name << " !"; + what=oss.str(); + return false; + } + if(_description!=other->_description) + { + std::ostringstream oss; oss << "Description differs : " << _description << " != " << other->_description << " !"; + what=oss.str(); + return false; + } + const MEDFileEquivalenceCell *c1(_cell),*c2(other->_cell); + if((c1 && !c2) || (!c1 && c2)) + { + std::ostringstream oss; oss << "Cell def of Equiv " << _name << " are defined for this and not for other (or reversely) !"; + what=oss.str(); + return false; + } + if(c1 && c2) + if(!c1->isEqual(c2,what)) + return false; + const MEDFileEquivalenceNode *n1(_node),*n2(other->_node); + if((n1 && !n2) || (!n1 && n2)) + { + std::ostringstream oss; oss << "Node def of Equiv " << _name << " are defined for this and not for other (or reversely) !"; + what=oss.str(); + return false; + } + if(n1 && n2) + if(!n1->isEqual(n2,what)) + return false; + return true; +} + +void MEDFileEquivalencePair::getRepr(std::ostream& oss) const +{ + const MEDFileEquivalenceNode *node(_node); + const MEDFileEquivalenceCell *cell(_cell); + oss << std::endl << " name of equivalence : " << _name << std::endl; + oss << " description of equivalence : " << _description << std::endl; + oss << " Node : "; + if(!node) + oss << "None" << std::endl; + else + node->getRepr(oss); + oss << " Cell : "; + if(!cell) + oss << "None" << std::endl; + else + cell->getRepr(oss); +} + MEDFileEquivalencePair *MEDFileEquivalencePair::New(MEDFileEquivalences *father, const std::string& name) { return new MEDFileEquivalencePair(father,name,std::string()); @@ -237,6 +304,58 @@ MEDFileEquivalencePair *MEDFileEquivalences::appendEmptyEquivalenceWithName(cons return elt; } +MEDFileEquivalences *MEDFileEquivalences::deepCpy(MEDFileMesh *owner) const +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileEquivalences(owner)); + ret->deepCpyFrom(*this); + return ret.retn(); +} + +bool MEDFileEquivalences::isEqual(const MEDFileEquivalences *other, std::string& what) const +{ + std::size_t sz(_equ.size()); + if(sz!=other->_equ.size()) + { + what="Equivalences differs : not same number !"; + return false; + } + for(std::size_t i=0;i_equ[i]); + if(!thisp && !otherp) + continue; + if(thisp && otherp) + { + if(!thisp->isEqual(otherp,what)) + { + std::ostringstream oss; oss << "At Eq #" << i << " there is a difference !"; + what=oss.str()+what; + return false; + } + } + else + { + std::ostringstream oss; oss << "At Eq #" << i << " defined in this not is other (or reversely) !"; + what=oss.str()+what; + return false; + } + } +} + +void MEDFileEquivalences::getRepr(std::ostream& oss) const +{ + std::size_t ii(0); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_equ.begin();it!=_equ.end();it++,ii++) + { + const MEDFileEquivalencePair *elt(*it); + oss << "Equivalence #" << ii << " : " ; + if(elt) + elt->getRepr(oss); + else + oss << "None" << std::endl; + } +} + void MEDFileEquivalences::killEquivalenceWithName(const std::string& name) { std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it(_equ.begin()); @@ -319,6 +438,20 @@ void MEDFileEquivalences::CheckDataArray(const DataArrayInt *data) } } +void MEDFileEquivalences::deepCpyFrom(const MEDFileEquivalences& other) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=other._equ.begin();it!=other._equ.end();it++) + { + const MEDFileEquivalencePair *elt(*it); + MEDCouplingAutoRefCountObjectPtr eltCpy; + if(elt) + { + eltCpy=elt->deepCpy(this); + } + _equ.push_back(eltCpy); + } +} + MEDFileEquivalenceBase::MEDFileEquivalenceBase(MEDFileEquivalencePair *father):_father(father) { } @@ -344,6 +477,22 @@ std::vector MEDFileEquivalenceData::getDirectChildrenWi return ret; } +bool MEDFileEquivalenceData::isEqual(const MEDFileEquivalenceData *other, std::string& what) const +{ + const DataArrayInt *d1(_data),*d2(other->_data); + if((!d1 && d2) || (d1 && !d2)) + { + what="Data array is defined in this not in other (or reversely) !"; + return false; + } + if(d1 && d2) + { + if(!d1->isEqualIfNotWhy(*d2,what)) + return false; + } + return true; +} + void MEDFileEquivalenceData::writeLL(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const { @@ -369,6 +518,36 @@ std::size_t MEDFileEquivalenceCellType::getHeapMemorySizeWithoutChildren() const return sizeof(MEDFileEquivalenceCellType); } +MEDFileEquivalenceCellType *MEDFileEquivalenceCellType::deepCpy(MEDFileEquivalencePair *owner) const +{ + MEDCouplingAutoRefCountObjectPtr da; + if(getArray()) + da=getArray()->deepCpy(); + return new MEDFileEquivalenceCellType(owner,_type,da); +} + +bool MEDFileEquivalenceCellType::isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const +{ + if(_type!=other->_type) + { + what="Geo types differs !"; + return false; + } + return MEDFileEquivalenceData::isEqual(other,what); +} + +void MEDFileEquivalenceCellType::getRepr(std::ostream& oss) const +{ + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_type)); + const DataArrayInt *da(getArray()); + oss << cm.getRepr() << ":"; + if(da) + oss << da->getNumberOfTuples() << " tuples"; + else + oss << "no dataarray"; + oss << ","; +} + void MEDFileEquivalenceCellType::write(med_idt fid) const { writeLL(fid,MED_CELL,typmai3[_type]); @@ -408,6 +587,61 @@ void MEDFileEquivalenceCell::write(med_idt fid) const } } +MEDFileEquivalenceCell *MEDFileEquivalenceCell::deepCpy(MEDFileEquivalencePair *owner) const +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileEquivalenceCell(owner)); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_types.begin();it!=_types.end();it++) + { + const MEDFileEquivalenceCellType *elt(*it); + MEDCouplingAutoRefCountObjectPtr eltCpy; + if(elt) + eltCpy=elt->deepCpy(owner); + ret->_types.push_back(eltCpy); + } + return ret.retn(); +} + +bool MEDFileEquivalenceCell::isEqual(const MEDFileEquivalenceCell *other, std::string& what) const +{ + std::size_t sz(_types.size()); + if(sz!=other->_types.size()) + { + std::ostringstream oss; oss << "Nb of geo types differs : " << sz << " != " << other->_types.size(); + what=oss.str(); + return false; + } + for(std::size_t i=0;i_types[i]); + if((ct1 && !ct2) || (!ct1 && ct2)) + { + std::ostringstream oss; oss << "At gt #" << i << " this is defined not other (or reversely !)"; + what=oss.str(); + return false; + } + if(ct1 && ct2) + { + if(!ct1->isEqual(ct2,what)) + { + std::ostringstream oss; oss << "At gt #" << i << " of Eq " << getFather()->getName() << " it differs !"; + what=oss.str()+what; + return false; + } + } + } + return true; +} + +void MEDFileEquivalenceCell::getRepr(std::ostream& oss) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_types.begin();it!=_types.end();it++) + { + const MEDFileEquivalenceCellType *elt(*it); + if(elt) + elt->getRepr(oss); + } +} + DataArrayInt *MEDFileEquivalenceCell::getArray(INTERP_KERNEL::NormalizedCellType type) { for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_types.begin();it!=_types.end();it++) @@ -510,3 +744,26 @@ void MEDFileEquivalenceNode::write(med_idt fid) const { writeLL(fid,MED_NODE,MED_NONE); } + +MEDFileEquivalenceNode *MEDFileEquivalenceNode::deepCpy(MEDFileEquivalencePair *owner) const +{ + MEDCouplingAutoRefCountObjectPtr da; + if(getArray()) + da=getArray()->deepCpy(); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileEquivalenceNode(owner,da)); + return ret.retn(); +} + +bool MEDFileEquivalenceNode::isEqual(const MEDFileEquivalenceNode *other, std::string& what) const +{ + return MEDFileEquivalenceData::isEqual(other,what); +} + +void MEDFileEquivalenceNode::getRepr(std::ostream& oss) const +{ + const DataArrayInt *da(getArray()); + if(!da) + oss << " No dataarray defined !" << std::endl; + else + oss << da->getNumberOfTuples() << " tuples in node equivalence." << std::endl; +} diff --git a/src/MEDLoader/MEDFileEquivalence.hxx b/src/MEDLoader/MEDFileEquivalence.hxx index be352bec5..bcf14904b 100644 --- a/src/MEDLoader/MEDFileEquivalence.hxx +++ b/src/MEDLoader/MEDFileEquivalence.hxx @@ -45,6 +45,9 @@ namespace ParaMEDMEM MEDFileEquivalences *getFather() { return _father; } const MEDFileMesh *getMesh() const; MEDFileMesh *getMesh(); + MEDFileEquivalencePair *deepCpy(MEDFileEquivalences *father) const; + bool isEqual(const MEDFileEquivalencePair *other, std::string& what) const; + void getRepr(std::ostream& oss) const; static MEDFileEquivalencePair *New(MEDFileEquivalences *father, const std::string& name); MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; @@ -80,6 +83,9 @@ namespace ParaMEDMEM std::string getMeshName() const; void pushEquivalence(MEDFileEquivalencePair *elt); static MEDFileEquivalences *New(MEDFileMesh *owner) { return new MEDFileEquivalences(owner); } + MEDFileEquivalences *deepCpy(MEDFileMesh *owner) const; + bool isEqual(const MEDFileEquivalences *other, std::string& what) const; + void getRepr(std::ostream& oss) const; public: MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalence(int i); MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalenceWithName(const std::string& name); @@ -96,6 +102,7 @@ namespace ParaMEDMEM static void CheckDataArray(const DataArrayInt *data); private: MEDFileEquivalences(MEDFileMesh *owner):_owner(owner) { } + void deepCpyFrom(const MEDFileEquivalences& other); private: MEDFileMesh *_owner; std::vector< MEDCouplingAutoRefCountObjectPtr > _equ; @@ -123,6 +130,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT const DataArrayInt *getArray() const { return _data; } MEDLOADER_EXPORT DataArrayInt *getArray() { return _data; } MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + bool isEqual(const MEDFileEquivalenceData *other, std::string& what) const; protected: void writeLL(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const; protected: @@ -137,6 +145,9 @@ namespace ParaMEDMEM MEDFileEquivalenceCellType(MEDFileEquivalencePair *owner, INTERP_KERNEL::NormalizedCellType type, DataArrayInt *data):MEDFileEquivalenceData(owner,data),_type(type) { } MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; INTERP_KERNEL::NormalizedCellType getType() const { return _type; } + MEDFileEquivalenceCellType *deepCpy(MEDFileEquivalencePair *owner) const; + bool isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const; + void getRepr(std::ostream& oss) const; public: void write(med_idt fid) const; private: @@ -152,6 +163,9 @@ namespace ParaMEDMEM MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; static MEDFileEquivalenceCell *Load(med_idt fid, MEDFileEquivalencePair *owner); void write(med_idt fid) const; + MEDFileEquivalenceCell *deepCpy(MEDFileEquivalencePair *owner) const; + bool isEqual(const MEDFileEquivalenceCell *other, std::string& what) const; + void getRepr(std::ostream& oss) const; public: MEDLOADER_EXPORT void clear() { _types.clear(); } MEDLOADER_EXPORT std::size_t size() const { return _types.size(); } @@ -176,6 +190,9 @@ namespace ParaMEDMEM MEDFileEquivalenceNode(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceData(owner,data) { } MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; void write(med_idt fid) const; + MEDFileEquivalenceNode *deepCpy(MEDFileEquivalencePair *owner) const; + bool isEqual(const MEDFileEquivalenceNode *other, std::string& what) const; + void getRepr(std::ostream& oss) const; private: ~MEDFileEquivalenceNode() { } }; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 619b3e4bd..761578f27 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -252,6 +252,8 @@ bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& wha return false; if(!areFamsEqual(other,what)) return false; + if(!areEquivalencesEqual(other,what)) + return false; return true; } @@ -2239,6 +2241,7 @@ MEDFileMesh *MEDFileUMesh::createNewEmpty() const MEDFileMesh *MEDFileUMesh::deepCpy() const { MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMesh(*this); + ret->deepCpyEquivalences(*this); if((const DataArrayDouble*)_coords) ret->_coords=_coords->deepCpy(); if((const DataArrayInt*)_fam_coords) @@ -2483,6 +2486,36 @@ void MEDFileMesh::loadEquivalences(med_idt fid) _equiv=MEDFileEquivalences::Load(fid,nbOfEq,this); } +void MEDFileMesh::deepCpyEquivalences(const MEDFileMesh& other) +{ + const MEDFileEquivalences *equiv(other._equiv); + if(equiv) + _equiv=equiv->deepCpy(this); +} + +bool MEDFileMesh::areEquivalencesEqual(const MEDFileMesh *other, std::string& what) const +{ + const MEDFileEquivalences *thisEq(_equiv),*otherEq(other->_equiv); + if(!thisEq && !otherEq) + return true; + if(thisEq && otherEq) + return thisEq->isEqual(otherEq,what); + else + { + what+="Equivalence differs : defined in this and not in other (or reversely) !"; + return false; + } +} + +void MEDFileMesh::getEquivalencesRepr(std::ostream& oss) const +{ + const MEDFileEquivalences *equiv(_equiv); + if(!equiv) + return ; + oss << "(******************************)\n(* EQUIVALENCES OF THE MESH : *)\n(******************************)\n"; + _equiv->getRepr(oss); +} + /*! * \brief Return number of joints, which is equal to number of adjacent mesh domains */ @@ -2954,6 +2987,7 @@ std::string MEDFileUMesh::simpleRepr() const } oss << std::endl << std::endl; getFamilyRepr(oss); + getEquivalencesRepr(oss); return oss.str(); } @@ -5988,6 +6022,7 @@ MEDFileMesh *MEDFileCMesh::createNewEmpty() const MEDFileMesh *MEDFileCMesh::deepCpy() const { MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + ret->deepCpyEquivalences(*this); if((const MEDCouplingCMesh*)_cmesh) ret->_cmesh=static_cast(_cmesh->deepCpy()); ret->deepCpyAttributes(); @@ -6203,6 +6238,7 @@ MEDFileMesh *MEDFileCurveLinearMesh::createNewEmpty() const MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const { MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCurveLinearMesh(*this); + ret->deepCpyEquivalences(*this); if((const MEDCouplingCurveLinearMesh*)_clmesh) ret->_clmesh=static_cast(_clmesh->deepCpy()); ret->deepCpyAttributes(); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 496088da6..65c39d1c2 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -177,6 +177,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT void setJoints( MEDFileJoints* joints ); MEDFileEquivalences *getEquivalences() { return _equiv; } const MEDFileEquivalences *getEquivalences() const { return _equiv; } + void killEquivalences() { _equiv=(MEDFileEquivalences *)0; } void initializeEquivalences() { _equiv=MEDFileEquivalences::New(this); } protected: MEDFileMesh(); @@ -201,6 +202,9 @@ namespace ParaMEDMEM void writeJoints(med_idt fid) const; void loadJointsFromFile(med_idt fid, MEDFileJoints *toUseInstedOfReading=0); void loadEquivalences(med_idt fid); + void deepCpyEquivalences(const MEDFileMesh& other); + bool areEquivalencesEqual(const MEDFileMesh *other, std::string& what) const; + void getEquivalencesRepr(std::ostream& oss) const; protected: int _order; int _iteration; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 0c838c550..310810e20 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -976,6 +976,7 @@ namespace ParaMEDMEM MEDFileJoints *getJoints(); void setJoints( MEDFileJoints* joints ); void initializeEquivalences(); + void killEquivalences(); %extend { std::string __str__() const throw(INTERP_KERNEL::Exception)