-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
_coords->alloc(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;i<spaceDim;i++)
_coords->setInfoOnComponent(i,infosOnComp[i].c_str());
}
_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 ;
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
return true;
}
+bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::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()
{
}
_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)
{
}
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;i<sz;i++)
+ w=std::copy(v[i]->getNames()->getConstPointer(),v[i]->getNames()->getConstPointer()+v[i]->getNames()->getNbOfElems(),w);
+ }
}
MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
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;
}
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();
}
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;
}
return _rev_num;
}
+const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
+{
+ return _names;
+}
+
void MEDFileUMeshSplitL1::eraseFamilyField()
{
_fam->fillWithZero();
int nbCells=(*it)->getNumberOfCells();
int end=start+nbCells;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> 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<DataArrayAsciiChar *>(_names->substr(start,end));
+ MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num,names);
start=end;
}
}
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)