From: ageay Date: Wed, 20 Mar 2013 11:14:32 +0000 (+0000) Subject: names of cells and nodes now available in MEDFileMesh classes X-Git-Tag: V6_main_FINAL~263 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=30e049fa9737dbaac6e5337abfc51788dac63bb4;p=tools%2Fmedcoupling.git names of cells and nodes now available in MEDFileMesh classes --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index fe3be7088..8b0cfc174 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1439,6 +1439,8 @@ std::size_t MEDFileUMesh::getHeapMemorySize() const ret+=_num_coords->getHeapMemorySize(); if((const DataArrayInt *)_rev_num_coords) ret+=_rev_num_coords->getHeapMemorySize(); + if((const DataArrayAsciiChar *)_name_coords) + ret+=_name_coords->getHeapMemorySize(); ret+=_ms.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr)); for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) if((const MEDFileUMeshSplitL1*) *it) @@ -1463,6 +1465,8 @@ MEDFileMesh *MEDFileUMesh::deepCpy() const throw(INTERP_KERNEL::Exception) ret->_num_coords=_num_coords->deepCpy(); if((const DataArrayInt*)_rev_num_coords) ret->_rev_num_coords=_rev_num_coords->deepCpy(); + if((const DataArrayAsciiChar*)_name_coords) + ret->_name_coords=_name_coords->deepCpy(); std::size_t i=0; for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) { @@ -1532,6 +1536,22 @@ bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& wh return false; } } + const DataArrayAsciiChar *namec1=_name_coords; + const DataArrayAsciiChar *namec2=otherC->_name_coords; + if((namec1==0 && namec2!=0) || (namec1!=0 && namec2==0)) + { + what="Mismatch of naming arr on nodes ! One is defined and not other !"; + return false; + } + if(namec1) + { + bool ret=namec1->isEqual(*namec2); + if(!ret) + { + what="Names arr on node differ !"; + return false; + } + } if(_ms.size()!=otherC->_ms.size()) { what="Number of levels differs !"; @@ -1569,6 +1589,9 @@ void MEDFileUMesh::clearNonDiscrAttributes() const const DataArrayInt *numc1=_num_coords; if(numc1) (const_cast(numc1))->setName("");//This parameter is not discriminant for comparison + const DataArrayAsciiChar *namc1=_name_coords; + if(namc1) + (const_cast(namc1))->setName("");//This parameter is not discriminant for comparison for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) { const MEDFileUMeshSplitL1 *tmp=(*it); @@ -1624,6 +1647,7 @@ void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int _coords=loaderl2.getCoords(); _fam_coords=loaderl2.getCoordsFamily(); _num_coords=loaderl2.getCoordsNum(); + _name_coords=loaderl2.getCoordsName(); computeRevNum(); } @@ -1651,7 +1675,7 @@ void MEDFileUMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit); - MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords); + MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords); for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) if((const MEDFileUMeshSplitL1 *)(*it)!=0) (*it)->write(fid,maa,mdim); @@ -1934,6 +1958,14 @@ const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) return l1->getNumberField(); } +const DataArrayAsciiChar *MEDFileUMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + return _name_coords; + const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + return l1->getNameField(); +} + int MEDFileUMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception) { const DataArrayDouble *coo=_coords; @@ -2405,12 +2437,15 @@ DataArrayInt *MEDFileUMesh::zipCoords() throw(INTERP_KERNEL::Exception) MEDCouplingAutoRefCountObjectPtr ret2=ret->invertArrayO2N2N2OBis(nbrOfNodesInUse); MEDCouplingAutoRefCountObjectPtr newCoords=coo->selectByTupleIdSafe(ret2->begin(),ret2->end()); MEDCouplingAutoRefCountObjectPtr newFamCoords; + MEDCouplingAutoRefCountObjectPtr newNameCoords; if((const DataArrayInt *)_fam_coords) newFamCoords=_fam_coords->selectByTupleIdSafe(ret2->begin(),ret2->end()); MEDCouplingAutoRefCountObjectPtr newNumCoords; if((const DataArrayInt *)_num_coords) newNumCoords=_num_coords->selectByTupleIdSafe(ret2->begin(),ret2->end()); - _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _rev_num_coords=0; + if((const DataArrayAsciiChar *)_name_coords) + newNameCoords=static_cast(_name_coords->selectByTupleIdSafe(ret2->begin(),ret2->end())); + _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _name_coords=newNameCoords; _rev_num_coords=0; for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_ms.begin();it!=_ms.end();it++) { if((MEDFileUMeshSplitL1*)*it) @@ -2708,6 +2743,33 @@ void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumA return _ms[traducedRk]->setRenumArr(renumArr); } +void MEDFileUMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt==1) + { + if(!nameArr) + { + _name_coords=0; + return ; + } + DataArrayDouble *coo(_coords); + if(!coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !"); + nameArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),MED_SNAME_SIZE,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! "); + nameArr->incrRef(); + _name_coords=nameArr; + return ; + } + if(meshDimRelToMaxExt>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !"); + int traducedRk=-meshDimRelToMaxExt; + if(traducedRk>=(int)_ms.size()) + throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !"); + if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0) + throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !"); + return _ms[traducedRk]->setNameArr(nameArr); +} + void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const { for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) @@ -2886,6 +2948,38 @@ bool MEDFileStructuredMesh::isEqual(const MEDFileMesh *other, double eps, std::s return false; } } + const DataArrayAsciiChar *d1=_names_cells; + const DataArrayAsciiChar *d2=otherC->_names_cells; + if((d1==0 && d2!=0) || (d1!=0 && d2==0)) + { + what="Mismatch of naming arr on cells ! One is defined and not other !"; + return false; + } + if(d1) + { + bool ret=d1->isEqual(*d2); + if(!ret) + { + what="Naming arr on cells differ !"; + return false; + } + } + d1=_names_nodes; + d2=otherC->_names_nodes; + if((d1==0 && d2!=0) || (d1!=0 && d2==0)) + { + what="Mismatch of naming arr on nodes ! One is defined and not other !"; + return false; + } + if(d1) + { + bool ret=d1->isEqual(*d2); + if(!ret) + { + what="Naming arr on nodes differ !"; + return false; + } + } return true; } @@ -2957,13 +3051,13 @@ void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayI if(meshDimRelToMaxExt==0) { int nbCells=mesh->getNumberOfCells(); - famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); _fam_cells=famArr; } else { int nbNodes=mesh->getNumberOfNodes(); - famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); _fam_nodes=famArr; } if(famArr) @@ -2986,13 +3080,36 @@ void MEDFileStructuredMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayIn else { int nbNodes=mesh->getNumberOfNodes(); - renumArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + renumArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); _num_nodes=renumArr; } if(renumArr) renumArr->incrRef(); } +void MEDFileStructuredMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : Only available for levels 0 or 1 !"); + const MEDCouplingStructuredMesh *mesh=getStructuredMesh(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : no structured mesh specified ! Impossible to set names array !"); + if(meshDimRelToMaxExt==0) + { + int nbCells=mesh->getNumberOfCells(); + nameArr->checkNbOfTuplesAndComp(nbCells,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of cells of mesh !"); + _names_cells=nameArr; + } + else + { + int nbNodes=mesh->getNumberOfNodes(); + nameArr->checkNbOfTuplesAndComp(nbNodes,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of nodes of mesh !"); + _names_nodes=nameArr; + } + if(nameArr) + nameArr->incrRef(); +} + const DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) @@ -3043,6 +3160,16 @@ const DataArrayInt *MEDFileStructuredMesh::getRevNumberFieldAtLevel(int meshDimR } } +const DataArrayAsciiChar *MEDFileStructuredMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNameFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) + return _names_cells; + else + return _names_nodes; +} + std::vector MEDFileStructuredMesh::getNonEmptyLevels() const { std::vector ret(1); @@ -3193,6 +3320,22 @@ void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt _num_cells->alloc(nbOfElt,1); MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NAME,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _names_cells=DataArrayAsciiChar::New(); + _names_cells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + MEDmeshEntityNameRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_names_cells->getPointer()); + _names_cells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NAME,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _names_nodes=DataArrayAsciiChar::New(); + _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer()); + _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + } } void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception) @@ -3208,6 +3351,26 @@ void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const char *maa) cons MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_num_cells->getNumberOfTuples(),_num_cells->getConstPointer()); if((const DataArrayInt *)_num_nodes) MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_num_nodes->getNumberOfTuples(),_num_nodes->getConstPointer()); + if((const DataArrayAsciiChar *)_names_cells) + { + if(_names_cells->getNumberOfComponents()!=MED_SNAME_SIZE) + { + std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on cells with number of components set to " << MED_SNAME_SIZE; + oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDmeshEntityNameWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_names_cells->getNumberOfTuples(),_names_cells->getConstPointer()); + } + if((const DataArrayAsciiChar *)_names_nodes) + { + if(_names_nodes->getNumberOfComponents()!=MED_SNAME_SIZE) + { + std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE; + oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDmeshEntityNameWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_names_nodes->getNumberOfTuples(),_names_nodes->getConstPointer()); + } // MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); } diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index b8656a6b7..ccd19ddf7 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -118,9 +118,11 @@ namespace ParaMEDMEM virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) throw(INTERP_KERNEL::Exception); virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) = 0; virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) = 0; + virtual void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception) = 0; virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; + virtual const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); @@ -184,6 +186,7 @@ namespace ParaMEDMEM const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); int getNumberOfNodes() const throw(INTERP_KERNEL::Exception); std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; @@ -214,6 +217,7 @@ namespace ParaMEDMEM void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception); void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception); void addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception); void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception); void removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception); @@ -245,6 +249,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _coords; MEDCouplingAutoRefCountObjectPtr _fam_coords; MEDCouplingAutoRefCountObjectPtr _num_coords; + MEDCouplingAutoRefCountObjectPtr _name_coords; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; }; @@ -261,8 +266,10 @@ namespace ParaMEDMEM const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception); const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); @@ -280,8 +287,10 @@ namespace ParaMEDMEM private: MEDCouplingAutoRefCountObjectPtr _fam_nodes; MEDCouplingAutoRefCountObjectPtr _num_nodes; + MEDCouplingAutoRefCountObjectPtr _names_nodes; MEDCouplingAutoRefCountObjectPtr _fam_cells; MEDCouplingAutoRefCountObjectPtr _num_cells; + MEDCouplingAutoRefCountObjectPtr _names_cells; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_nodes; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_cells; }; diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 33d14b9f3..6d095832c 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -94,13 +94,26 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int _conn_index=DataArrayInt::New(); _conn_index->alloc(curNbOfElem+1,1); INTERP_KERNEL::AutoPtr connTab=new int[(nbOfNodesPerCell)*curNbOfElem]; - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); + MEDmeshElementConnectivityRd(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,connTab); + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + *w2++=0; + const int *wi=connTab; + for(int i=0;i(),-1)); + *w2=w2[-1]+nbOfNodesPerCell+1; + } +} + +void MEDFileUMeshPerType::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, + med_entity_type entity) +{ + med_bool changement,transformation; _fam=DataArrayInt::New(); _fam->alloc(curNbOfElem,1); - med_bool changement,transformation; - INTERP_KERNEL::AutoPtr noms=new char[MED_SNAME_SIZE*(std::size_t)curNbOfElem+1]; - MEDmeshElementConnectivityRd(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,connTab); if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) { if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0) @@ -117,15 +130,14 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int } else _num=0; - int *w1=_conn->getPointer(); - int *w2=_conn_index->getPointer(); - *w2++=0; - const int *wi=connTab; - for(int i=0;i0) { - *w1++=(int)type; - w1=std::transform(wi,wi+nbOfNodesPerCell,w1,std::bind2nd(std::plus(),-1)); - *w2=w2[-1]+nbOfNodesPerCell+1; + _names=DataArrayAsciiChar::New(); + _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0) + _names=0; + else + _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end } } @@ -138,10 +150,6 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int _conn_index->alloc(curNbOfElem+1,1); _conn=DataArrayInt::New(); _conn->alloc(arraySize+curNbOfElem,1); - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); - _fam=DataArrayInt::New(); - _fam->alloc(curNbOfElem,1); INTERP_KERNEL::AutoPtr locConn=new int[arraySize]; MEDmeshPolygonRd(fid,mName,dt,it,MED_CELL,MED_NODAL,_conn_index->getPointer(),locConn); int *w1=_conn->getPointer(); @@ -156,20 +164,7 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int *w2=*w2-1+i; } *w2=*w2-1+curNbOfElem; - if(MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,MED_POLYGON,_fam->getPointer())!=0) - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); - } - else - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); - if(MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYGON,_num->getPointer())!=0) - _num=0; - } - else - _num=0; + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYGON,entity); } void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, @@ -181,16 +176,7 @@ void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int INTERP_KERNEL::AutoPtr index=new int[curNbOfElem+1]; INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth]; - _fam=DataArrayInt::New(); - _fam->alloc(curNbOfElem,1); MEDmeshPolyhedronRd(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn); - if(MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,MED_POLYHEDRON,_fam->getPointer())!=0) - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); - } - else - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); int arraySize=connFaceLgth; for(int i=0;i(),-1)); } } - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); - if(MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYHEDRON,_num->getPointer())!=0) - _num=0; - } - else - _num=0; + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYHEDRON,entity); } -void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num) +void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names) { int nbOfCells=m->getNumberOfCells(); if(nbOfCells<1) @@ -293,4 +271,14 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,fam->getConstPointer()); if(num) MEDmeshEntityNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,num->getConstPointer()); + if(names) + { + if(names->getNumberOfComponents()!=MED_SNAME_SIZE) + { + std::ostringstream oss; oss << "MEDFileUMeshPerType::write : expected a name field on cells with number of components set to " << MED_SNAME_SIZE; + oss << " ! The array has " << names->getNumberOfComponents() << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDmeshEntityNameWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,names->getConstPointer()); + } } diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index fcce83e75..4db89c9e9 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -43,7 +43,8 @@ namespace ParaMEDMEM const DataArrayInt *getNodalIndex() const { return _conn_index; } const DataArrayInt *getFam() const { return _fam; } const DataArrayInt *getNum() const { return _num; } - static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num); + const DataArrayAsciiChar *getNames() const { return _names; } + static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names); private: MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, med_entity_type entity); @@ -53,11 +54,13 @@ namespace ParaMEDMEM med_entity_type entity); void loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, med_entity_type entity); + void loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity); private: MEDCouplingAutoRefCountObjectPtr _conn; MEDCouplingAutoRefCountObjectPtr _conn_index; MEDCouplingAutoRefCountObjectPtr _num; MEDCouplingAutoRefCountObjectPtr _fam; + MEDCouplingAutoRefCountObjectPtr _names; INTERP_KERNEL::NormalizedCellType _type; med_entity_type _entity; }; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index e6851db84..25208ea31 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -266,18 +266,31 @@ void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vectoralloc(nCoords,spaceDim); double *coordsPtr=_coords->getPointer(); MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,coordsPtr); - _fam_coords=DataArrayInt::New(); - _fam_coords->alloc(nCoords,1); - _num_coords=DataArrayInt::New(); - _num_coords->alloc(nCoords,1); if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()); + { + _fam_coords=DataArrayInt::New(); + _fam_coords->alloc(nCoords,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()); + } else _fam_coords=0; if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) - MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()); + { + _num_coords=DataArrayInt::New(); + _num_coords->alloc(nCoords,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()); + } else _num_coords=0; + if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0) + { + _name_coords=DataArrayAsciiChar::New(); + _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()); + _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end + } + else + _name_coords=0; for(int i=0;isetInfoOnComponent(i,infosOnComp[i].c_str()); } @@ -315,7 +328,7 @@ void MEDFileUMeshL2::sortTypes() _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev); } -void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords) +void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords) { if(!coords) return ; @@ -324,6 +337,16 @@ void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()); if(numCoords) MEDmeshEntityNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()); + if(nameCoords) + { + if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE) + { + std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE; + oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDmeshEntityNameWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()); + } } bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const @@ -342,6 +365,14 @@ bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const return true; } +bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++) + if((*it)->getNames()==0) + return false; + return true; +} + MEDFileCMeshL2::MEDFileCMeshL2() { } @@ -465,7 +496,7 @@ void MEDFileUMeshPermCompute::updateTime() const _num_time=_st->_num->getTimeOfThis(); } -MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_rev_num(other._rev_num),_m(this) +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_names(other._names),_rev_num(other._rev_num),_m(this) { } @@ -506,6 +537,15 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *m w=std::copy(v[i]->getNum()->getConstPointer(),v[i]->getNum()->getConstPointer()+v[i]->getNum()->getNumberOfTuples(),w); computeRevNum(); } + if(l2.isNamesDefinedOnLev(id)) + { + int nbOfCells=_m_by_types->getNumberOfCells(); + _names=DataArrayAsciiChar::New(); + _names->alloc(nbOfCells,MED_SNAME_SIZE); + char *w=_names->getPointer(); + for(int i=0;igetNames()->getConstPointer(),v[i]->getNames()->getConstPointer()+v[i]->getNames()->getNbOfElems(),w); + } } MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this) @@ -527,12 +567,14 @@ std::size_t MEDFileUMeshSplitL1::getHeapMemorySize() const if((const DataArrayDouble *)_m_by_types->getCoords()) ret-=_m_by_types->getCoords()->getHeapMemorySize(); } - if((const DataArrayInt*)_fam) + if((const DataArrayInt*)_fam) ret+=_fam->getHeapMemorySize(); - if((const DataArrayInt*)_num) + if((const DataArrayInt*)_num) ret+=_num->getHeapMemorySize(); - if((const DataArrayInt*)_rev_num) + if((const DataArrayInt*)_rev_num) ret+=_rev_num->getHeapMemorySize(); + if((const DataArrayAsciiChar*)_names) + ret+=_names->getHeapMemorySize(); return ret; } @@ -547,6 +589,8 @@ MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy() const ret->_num=_num->deepCpy(); if((const DataArrayInt *)_rev_num) ret->_rev_num=_rev_num->deepCpy(); + if((const DataArrayAsciiChar *)_names) + ret->_names=_names->deepCpy(); return ret.retn(); } @@ -591,6 +635,19 @@ bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, what="Numbering cell arr at a sublevel are not deeply equal !"; return false; } + const DataArrayAsciiChar *e1=_names; + const DataArrayAsciiChar *e2=other->_names; + if((e1==0 && e2!=0) || (e1!=0 && e2==0)) + { + what="Presence of cell names arr in one sublevel and not in other!"; + return false; + } + if(e1) + if(!e1->isEqual(*e2)) + { + what="Name cell arr at a sublevel are not deeply equal !"; + return false; + } return true; } @@ -738,6 +795,11 @@ const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const return _rev_num; } +const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const +{ + return _names; +} + void MEDFileUMeshSplitL1::eraseFamilyField() { _fam->fillWithZero(); @@ -774,11 +836,14 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const int nbCells=(*it)->getNumberOfCells(); int end=start+nbCells; MEDCouplingAutoRefCountObjectPtr fam,num; + MEDCouplingAutoRefCountObjectPtr names; if((const DataArrayInt *)_fam) fam=_fam->substr(start,end); if((const DataArrayInt *)_num) num=_num->substr(start,end); - MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num); + if((const DataArrayAsciiChar *)_names) + names=static_cast(_names->substr(start,end)); + MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num,names); start=end; } } @@ -830,6 +895,21 @@ void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr) computeRevNum(); } +void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr) +{ + if(!nameArr) + { + _names=0; + return ; + } + MEDCouplingUMesh *mbt(_m_by_types); + if(!mbt) + throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::setNameArr : no mesh defined on this level !"); + nameArr->checkNbOfTuplesAndComp(mbt->getNumberOfCells(),MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! "); + nameArr->incrRef(); + _names=nameArr; +} + MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds) { if(renum==0) diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 07306af54..6cec701c0 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -72,10 +72,12 @@ namespace ParaMEDMEM const std::vector< MEDCouplingAutoRefCountObjectPtr >& getLev(int levId) const { return _per_type_mesh[levId]; } bool isFamDefinedOnLev(int levId) const; bool isNumDefinedOnLev(int levId) const; + bool isNamesDefinedOnLev(int levId) const; MEDCouplingAutoRefCountObjectPtr getCoords() const { return _coords; } MEDCouplingAutoRefCountObjectPtr getCoordsFamily() const { return _fam_coords; } MEDCouplingAutoRefCountObjectPtr getCoordsNum() const { return _num_coords; } - static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords); + MEDCouplingAutoRefCountObjectPtr getCoordsName() const { return _name_coords; } + static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords); private: void sortTypes(); private: @@ -83,6 +85,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _coords; MEDCouplingAutoRefCountObjectPtr _fam_coords; MEDCouplingAutoRefCountObjectPtr _num_coords; + MEDCouplingAutoRefCountObjectPtr _name_coords; }; class MEDFileStrMeshL2 : public MEDFileMeshL2 @@ -153,6 +156,7 @@ namespace ParaMEDMEM DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception); const DataArrayInt *getFamilyField() const; const DataArrayInt *getNumberField() const; + const DataArrayAsciiChar *getNameField() const; const DataArrayInt *getRevNumberField() const; void eraseFamilyField(); void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, @@ -161,6 +165,7 @@ namespace ParaMEDMEM // void setFamilyArr(DataArrayInt *famArr); void setRenumArr(DataArrayInt *renumArr); + void setNameArr(DataArrayAsciiChar *nameArr); void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); // void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception); @@ -179,6 +184,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _m_by_types; MEDCouplingAutoRefCountObjectPtr _fam; MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _names; mutable MEDCouplingAutoRefCountObjectPtr _rev_num; MEDFileUMeshPermCompute _m; }; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index a770f351e..1707f6625 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -437,6 +437,7 @@ namespace ParaMEDMEM virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + virtual void setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception); virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); @@ -524,6 +525,14 @@ namespace ParaMEDMEM tmp->incrRef(); return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } + + PyObject *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) + { + const DataArrayAsciiChar *tmp=self->getNameFieldAtLevel(meshDimRelToMaxExt); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar, SWIG_POINTER_OWN | 0 ); + } PyObject *findOrCreateAndGiveFamilyWithId(int id, bool& created) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index cdef0aa24..6725975be 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -2058,6 +2058,60 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(2,data2.getNumberOfParams()) self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13) pass + + def testNamesOnCellAndNodesInMeshes1(self): + fname="Pyfile58.med" + fname2="Pyfile59.med" + m=MEDLoaderDataForTest.build3DSurfMesh_1() + m1=m.buildDescendingConnectivity()[0] + m1.sortCellsInMEDFileFrmt() + # + mm=MEDFileUMesh() + mm.setMeshAtLevel(0,m) + mm.setMeshAtLevel(-1,m1) + namesCellL0=DataArrayAsciiChar(6,16) + namesCellL0[:]=["CellL0#%.3d "%(i) for i in xrange(6)] + mm.setNameFieldAtLevel(0,namesCellL0) + namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.substr(2)]) + namesCellL1[:]=["CellLM1#%.3d "%(i) for i in xrange(16)] + mm.setNameFieldAtLevel(-1,namesCellL1) + namesNodes=namesCellL1.substr(4,16) + namesNodes[:]=["Node#%.3d "%(i) for i in xrange(12)] + mm.setNameFieldAtLevel(1,namesNodes) + mm.write(fname,2) + # + mmr=MEDFileMesh.New(fname) + self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d "%(i) for i in xrange(6)]))) + self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d "%(i) for i in xrange(16)]))) + self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(12)]))) + self.assertTrue(mm.isEqual(mmr,1e-12)[0]) + mmr.getNameFieldAtLevel(1).setIJ(0,0,'M') + self.assertTrue(not mm.isEqual(mmr,1e-12)[0]) + mmr.getNameFieldAtLevel(1).setIJ(0,0,'N') + self.assertTrue(mm.isEqual(mmr,1e-12)[0]) + mmCpy=mm.deepCpy() + self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) + # + c=MEDCouplingCMesh() + arr=DataArrayDouble([0.,1.1,2.3]) + c.setCoords(arr,arr) + c.setName("cmesh") + cc=MEDFileCMesh() + cc.setMesh(c) + cc.setNameFieldAtLevel(0,DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)])) + cc.setNameFieldAtLevel(1,DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)])) + cc.write(fname2,2) + ccr=MEDFileMesh.New(fname2) + self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)]))) + self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)]))) + self.assertTrue(cc.isEqual(ccr,1e-12)[0]) + ccr.getNameFieldAtLevel(1).setIJ(0,0,'M') + self.assertTrue(not cc.isEqual(ccr,1e-12)[0]) + ccr.getNameFieldAtLevel(1).setIJ(0,0,'N') + self.assertTrue(cc.isEqual(ccr,1e-12)[0]) + ccCpy=cc.deepCpy() + self.assertTrue(cc.isEqual(ccCpy,1e-12)[0]) + pass pass unittest.main()