med_geometrie_element typmainoeud[1] = { MED_NONE };
-INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_ERROR,
+INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT0,
INTERP_KERNEL::NORM_SEG2,
INTERP_KERNEL::NORM_SEG3,
INTERP_KERNEL::NORM_TRI3,
void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn);
int buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type,
std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
- std::vector<int>& fam4MEDFile);
+ std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
- const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract) throw(INTERP_KERNEL::Exception);
+ const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception);
void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
+ const std::vector<int>& familiesToKeep,
DataArrayInt* &conn,
DataArrayInt* &connIndex,
- const std::vector<int>& familiesToKeep);
+ int *&cellRenum);
ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
const std::vector<std::string>& infos);
int buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families,
- std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile);
+ std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
int buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector<int>& conn4MEDFile,
std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
- std::vector<int>& fam4MEDFile);
+ std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
int buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families,
- INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile);
+ INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
ParaMEDMEM::TypeOfField typeOfOutField);
+ ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh,
+ const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
+ std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType);
med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt);
void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds);
void appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
void fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f);
- void writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch);
+ void writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch, bool &isRenumbering);
void writeUMeshesDirectly(const char *fileName, const char *meshName, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
/*!
* This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh.
*/
-void MEDLoader::setEpsilonForNodeComp(double val)
+void MEDLoader::setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception)
{
_EPS_FOR_NODE_COMP=val;
}
/*!
* This method sets the policy comparison when trying to fit the already written mesh on a field. The semantic of the policy is specified in MEDCouplingUMesh::zipConnectivityTraducer.
*/
-void MEDLoader::setCompPolicyForCell(int val)
+void MEDLoader::setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception)
{
_COMP_FOR_CELL=val;
}
* This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
* By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
*/
-void MEDLoader::setTooLongStrPolicy(int val)
+void MEDLoader::setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception)
{
_TOO_LONG_STR=val;
}
MEDfermer(fid);
}
-std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName)
+std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
{
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
return ret;
}
-std::vector<std::string> MEDLoader::GetMeshFamilyNames(const char *fileName, const char *meshName)
+std::vector<std::string> MEDLoader::GetMeshFamilyNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
med_int nfam=MEDnFam(fid,(char *)meshName);
return ret;
}
-std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName)
+std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
med_int nfam=MEDnFam(fid,(char *)meshName);
return ret;
}
-std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName)
+std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
std::vector<std::string> ret;
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
return ret;
}
-std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName)
+std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
std::vector<std::string> ret;
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
return ret;
}
-std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName)
+std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
switch(type)
{
}
}
-std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
+std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
return ret;
}
-std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
+std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
delete [] noms;
//trying to read global numbering
int *globArr=new int[curNbOfElem];
- if(MEDglobalNumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0)
+ if(MEDnumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0)
elem.setGlobal(globArr);
else
delete [] globArr;
int *index=new int[curNbOfPolyElem+1];
int *locConn=new int[arraySize];
int *fam=new int[curNbOfPolyElem];
+ int *globArr=new int[curNbOfPolyElem];
MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize);
MEDpolygoneConnLire(fid,nommaa,index,curNbOfPolyElem+1,locConn,whichPolyEntity,MED_NOD);
- MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYGONE);
+ MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE);
+ if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE)==0)
+ elem.setGlobal(globArr);
+ else
+ delete [] globArr;
conn.push_back(elem);
}
curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD);
int *indexFace=new int[indexFaceLgth];
int *locConn=new int[connFaceLgth];
int *fam=new int[curNbOfPolyElem];
+ int *globArr=new int[curNbOfPolyElem];
MEDpolyedreConnLire(fid,nommaa,index,curNbOfPolyElem+1,indexFace,indexFaceLgth,locConn,MED_NOD);
MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE);
int arraySize=connFaceLgth;
delete [] locConn;
delete [] indexFace;
MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
+ if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE)==0)
+ elem.setGlobal(globArr);
+ else
+ delete [] globArr;
conn.push_back(elem);
}
}
int _sigma;
};
+/*!
+ * This method fills unstructured connectivity using basic MED file format 'medConnFrmt'.
+ * If in each elements of 'medConnFrmt' a renumbering cell array is found the aggregate array 'cellRenum' is returned.
+ */
void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
+ const std::vector<int>& familiesToKeep,
DataArrayInt* &conn,
DataArrayInt* &connIndex,
- const std::vector<int>& familiesToKeep)
+ int *&cellRenum)
{
bool keepAll=familiesToKeep.empty();
if(medConnFrmt.empty())
{
conn=0;
connIndex=0;
+ cellRenum=0;
return ;
}
std::list<MEDLoader::MEDConnOfOneElemType>::const_iterator iter=medConnFrmt.begin();
int totalNbOfCells=0;
int totalNbOfMedConn=0;
+ bool renumber=true;
+ cellRenum=0;
for(;iter!=medConnFrmt.end();iter++)
{
+ if((*iter).getGlobal()==0)
+ renumber=false;
const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel((*iter).getType());
if(keepAll)
totalNbOfCells+=(*iter).getLength();
int connFillId=0;
conn->alloc(totalNbOfMedConn+totalNbOfCells,1);
int *connPtr=conn->getPointer();
+ if(renumber)
+ cellRenum=new int[totalNbOfCells];
+ int *renumW=cellRenum;
for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
{
INTERP_KERNEL::NormalizedCellType type=(*iter).getType();
const int *sourceConn=(*iter).getArray();
const int *sourceIndex=(*iter).getIndex();
+ const int *globalNum=(*iter).getGlobal();
const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type);
int nbOfCellsInCurType;
int nbOfNodesIn1Cell=cellMod.getNumberOfNodes();
for(int i=0;i<nbOfCellsInCurType;i++)
{
if(keepAll)
- {
+ {//duplication of next 3 lines needed.
*connIdxPtr=connFillId;
*connPtr++=type;
+ if(renumber)
+ *renumW++=globalNum[i];
if(!isDyn)
tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
else
connPtr=tmpConnPtr;
}
else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end())
- {
+ {//duplication of next 3 lines needed.
*connIdxPtr=connFillId;
*connPtr++=type;
+ if(renumber)
+ *renumW++=globalNum[i];
if(!isDyn)
tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
- else
+ else//The duplication of code is motivated by the line underneath.
tmpConnPtr=std::transform((*iter).getArray()+sourceIndex[i]-1,(*iter).getArray()+sourceIndex[i+1]-1,connPtr,std::bind2nd(std::minus<int>(),1));
connIdxPtr++;
nbOfNodesIn1Cell=tmpConnPtr-connPtr;
* @return nb of elements extracted.
*/
int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile,
- std::vector<int>& fam4MEDFile)
+ std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
{
int ret=0;
int nbOfElem=connIndex->getNbOfElems()-1;
conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
if(families)
fam4MEDFile.push_back(famPtr[i]);
+ renumber.push_back(i+1);
ret++;
}
connIdxPtr++;
}
int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile,
- std::vector<int>& fam4MEDFile)
+ std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
{
int ret=0;
int nbOfElem=connIndex->getNbOfElems()-1;
connIndex4MEDFile.push_back(connIndex4MEDFile.back()+delta-1);
if(families)
fam4MEDFile.push_back(famPtr[i]);
+ renumber.push_back(i+1);
ret++;
}
connIdxPtr++;
int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families,
std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
- std::vector<int>& fam4MEDFile)
+ std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
{
int ret=0;
int nbOfElem=connIndex->getNbOfElems()-1;
connIndexRk24MEDFile.push_back(connIndexRk24MEDFile.back()+nbOfFacesOfPolyh);
if(families)
fam4MEDFile.push_back(famPtr[i]);
+ renumber.push_back(i+1);
ret++;
}
connIdxPtr++;
*/
int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families,
INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile,
- std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile, std::vector<int>& fam4MEDFile)
+ std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
{
const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type);
if(!cellMod.isDynamic())
- return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile);
+ return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile,renumber);
else
{
if(type==INTERP_KERNEL::NORM_POLYGON)
- return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile);
+ return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile,renumber);
else
- return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile);
+ return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile,renumber);
}
}
* @param ids is a in vector containing families ids whose cells have to be kept. If empty all cells are kept.
* @param typesToKeep is a in vector that indicates which types to keep after dimension filtering.
* @param meshDimExtract out parameter that gives the mesh dimension.
+ * @param cellRenum out parameter that specifies the renumbering (if !=0) of cells in file.
*/
MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
- const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract) throw(INTERP_KERNEL::Exception)
+ const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception)
{
//Extraction data from MED file.
med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
coords->decrRef();
//
DataArrayInt *connArr,*connIndexArr;
- tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,connArr,connIndexArr,ids);
+ tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,ids,connArr,connIndexArr,cellRenum);
ret->setConnectivity(connArr,connIndexArr);
//clean-up
if(connArr)
return ret;
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
- ParaMEDMEM::TypeOfField typeOfOutField)
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh,
+ const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
+ std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType)
{
- std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
- double time;
- std::vector<std::string> infos;
- readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos);
- std::vector<int> familiesToKeep;
- std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
- if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
- for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
- typesToKeep.push_back((*iter).getType());
- unsigned meshDim;
- ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType,meshDim);
//for profiles
+ ParaMEDMEM::MEDCouplingUMesh *newMesh=0;
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
{
const std::vector<int>& cellIds=(*iter).getCellIdPerType();
{
std::vector<int> ci(cellIds.size());
std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus<int>(),-1));
- ParaMEDMEM::MEDCouplingUMesh *mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci);
- mesh->decrRef();
- mesh=mesh2;
+ ParaMEDMEM::MEDCouplingUMesh *mesh2;
+ if(newMesh)
+ mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci);
+ else
+ mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci);
+ if(newMesh)
+ newMesh->decrRef();
+ newMesh=mesh2;
}
}
//
ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME);
ret->setName(fieldName);
ret->setTime(time,iteration,order);
- ret->setMesh(mesh);
- mesh->decrRef();
+ if(newMesh)
+ {
+ ret->setMesh(newMesh);
+ newMesh->decrRef();
+ }
+ else
+ ret->setMesh(mesh);
ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos);
ret->setArray(arr);
arr->decrRef();
//
if(typeOfOutField==ON_GAUSS_PT)
fillGaussDataOnField(fileName,fieldPerCellType,ret);
- //
+ if(cellRenum)
+ ret->renumberCellsWithoutMesh(cellRenum,true);
+ return ret;
+}
+
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
+ ParaMEDMEM::TypeOfField typeOfOutField)
+{
+ std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
+ double time;
+ std::vector<std::string> infos;
+ readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos);
+ std::vector<int> familiesToKeep;
+ std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
+ if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
+ for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
+ typesToKeep.push_back((*iter).getType());
+ unsigned meshDim;
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
+ ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType);
+ if(cellRenum)
+ mesh->renumberCells(cellRenum,true);
+ mesh->decrRef();
+ //clean-up
+ delete [] cellRenum;
releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
return ret;
}
std::vector<int> familiesToKeep;
std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
unsigned meshDim;
- return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
+ if(cellRenum)
+ {
+ ret->renumberCells(cellRenum,true);
+ delete [] cellRenum;
+ }
+ return ret;
}
ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
std::vector<int> familiesToKeep;
std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
unsigned meshDim;
- return MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
+ if(cellRenum)
+ {
+ ret->renumberCells(cellRenum,true);
+ delete [] cellRenum;
+ }
+ return ret;
}
-int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName)
+int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
std::vector<int> poss;
return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
}
-ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
+ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
{
std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams);
std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
unsigned meshDim;
- ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
if(fams.size()==1)
ret->setName(fams.back().c_str());
+ if(cellRenum)
+ {
+ ret->renumberCells(cellRenum,true);
+ delete [] cellRenum;
+ }
return ret;
}
-ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
+ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
{
std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps);
std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
unsigned meshDim;
- ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
if(grps.size()==1)
ret->setName(grps.back().c_str());
+ if(cellRenum)
+ {
+ ret->renumberCells(cellRenum,true);
+ delete [] cellRenum;
+ }
return ret;
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
switch(type)
{
}
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsDoubleOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
+ const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
+ if(its.empty())
+ return ret;
+ //Retrieving mesh of rank 0 and field on rank 0 too.
+ std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
+ double time;
+ std::vector<std::string> infos;
+ MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[0].first,its[0].second,type,fieldPerCellType,time,infos);
+ std::vector<int> familiesToKeep;
+ std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
+ if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE)
+ for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
+ typesToKeep.push_back((*iter).getType());
+ unsigned meshDim;
+ int *cellRenum;
+ ParaMEDMEM::MEDCouplingUMesh *m1=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
+ ret[0]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[0].first,its[0].second,time,fieldPerCellType);
+ if(cellRenum)
+ m1->renumberCells(cellRenum,true);
+ MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
+ //
+ for(int itId=1;itId<its.size();itId++)
+ {
+ std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
+ double time;
+ std::vector<std::string> infos;
+ MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[itId].first,its[itId].second,type,fieldPerCellType,time,infos);
+ std::vector<int> familiesToKeep;
+ std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
+ if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE)
+ for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
+ typesToKeep.push_back((*iter).getType());
+ ret[itId]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[itId].first,its[itId].second,time,fieldPerCellType);
+ //clean-up
+ MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
+ }
+ m1->decrRef();
+ delete [] cellRenum;
+ return ret;
+}
+
+std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsDoubleCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
+ const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
+{
+ return ReadFieldsDoubleOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
+}
+
+std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsDoubleNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
+ const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
+{
+ return ReadFieldsDoubleOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
+}
+
+std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsDoubleGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
+ const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
+{
+ return ReadFieldsDoubleOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
+}
+
+std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsDoubleGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
+ const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
+{
+ return ReadFieldsDoubleOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
+}
+
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS);
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES);
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT);
}
-ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE);
}
-void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch)
+/*!
+ * @param families input parameter that specifies the field on int on each cells of 'mesh'.
+ * @param isRenumbering output parameter that specifies if a renumbering of mesh has been needed.
+ */
+void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch, bool &isRenumbering)
{
med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE);
std::string meshName(mesh->getName());
MEDfermer(fid);
throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !");
}
+ isRenumbering=!mesh->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
char *desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC);
MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR);
MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc);
MEDdimEspaceCr(fid,maa,spaceDim);
std::set<INTERP_KERNEL::NormalizedCellType> allTypes(mesh->getAllTypes());
- DataArrayInt *conn=mesh->getNodalConnectivity();
- DataArrayInt *connIndex=mesh->getNodalConnectivityIndex();
+ const DataArrayInt *conn=mesh->getNodalConnectivity();
+ const DataArrayInt *connIndex=mesh->getNodalConnectivityIndex();
char familyName[MED_TAILLE_NOM+1];
std::fill(familyName,familyName+MED_TAILLE_NOM+1,'\0');
const char DftFamilyName[]="DftFamily";
std::vector<int> medConnIndex;
std::vector<int> medConnIndex2;
std::vector<int> fam;
- int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam);
+ std::vector<int> renumber;
+ int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber);
if(curMedType!=MED_POLYGONE && curMedType!=MED_POLYEDRE)
MEDconnEcr(fid,maa,mesh->getMeshDimension(),&medConn[0],MED_FULL_INTERLACE,nbOfElt,MED_MAILLE,curMedType,MED_NOD);
else
}
if(families)
MEDfamEcr(fid,maa,&fam[0],nbOfElt,MED_MAILLE,curMedType);
+ if(isRenumbering)
+ MEDnumEcr(fid,maa,&renumber[0],nbOfElt,MED_MAILLE,curMedType);
}
}
MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0);
DataArrayInt *arr2=DataArrayInt::makePartition(corr,m->getNumberOfCells(),fidsOfGroups);
for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++)
(*it)->decrRef();
- writeUMeshDirectly(fileName,m,arr2,forceFromScratch);
+ bool isRenumbering;
+ writeUMeshDirectly(fileName,m,arr2,forceFromScratch,isRenumbering);
// families creation
std::set<int> familyIds;
for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++)
return fid;
}
-void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
+void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f2)
{
med_int numdt,numo;
med_float dt;
+ //renumbering
+ const ParaMEDMEM::MEDCouplingFieldDouble *f=f2;
+ const MEDCouplingMesh *mesh=f->getMesh();
+ const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
+ if(!meshC)
+ throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
+ bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ if(renum)
+ {
+ ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true);
+ DataArrayInt *da=meshC->getRenumArrForConsctvCellTypesSpe(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ f3->renumberCells(da->getConstPointer(),false);
+ da->decrRef();
+ f=f3;
+ }
+ //end renumbering
int nbComp=f->getNumberOfComponents();
med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
const double *pt=f->getArray()->getConstPointer();
}
delete [] nommaa;
MEDfermer(fid);
+ if(renum)
+ ((ParaMEDMEM::MEDCouplingFieldDouble *)f)->decrRef();
}
/*!
const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
if(!meshC)
throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
- if(!meshC->checkConsecutiveCellTypes())
+ if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2))
throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
const int *conn=meshC->getNodalConnectivity()->getConstPointer();
void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch)
{
+ f->checkCoherency();
std::string meshName(f->getMesh()->getName());
if(meshName.empty())
throw INTERP_KERNEL::Exception("Trying to write a mesh (f->getMesh()) with no name ! MED file format needs a not empty mesh name !");
if(fieldName.empty())
throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !");
MEDCouplingUMesh *mesh=dynamic_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)f->getMesh());
- writeUMeshDirectly(fileName,mesh,0,forceFromScratch);
- appendFieldDirectly(fileName,f);
+ if(mesh)
+ {
+ bool isRenumbering;
+ writeUMeshDirectly(fileName,mesh,0,forceFromScratch,isRenumbering);
+ if(isRenumbering)
+ {
+ ParaMEDMEM::MEDCouplingFieldDouble *f2=f->clone(true);
+ DataArrayInt *da=mesh->getRenumArrForConsctvCellTypesSpe(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ f2->renumberCells(da->getConstPointer(),false);
+ da->decrRef();
+ appendFieldDirectly(fileName,f2);
+ f2->decrRef();
+ }
+ else
+ appendFieldDirectly(fileName,f);
+ return ;
+ }
+ throw INTERP_KERNEL::Exception("The mesh underlying field is not unstructured ! Only unstructured mesh supported for writting now !");
}
/*!
m->decrRef();
}
-void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
+void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
{
std::string meshName(mesh->getName());
if(meshName.empty())
throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
int status=MEDLoaderBase::getStatusOfFile(fileName);
+ bool isRenumbering;
if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
{
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
}
if(writeFromScratch)
{
- MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true);
+ MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true,isRenumbering);
return ;
}
if(status==MEDLoaderBase::NOT_EXIST)
{
- MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true);
+ MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true,isRenumbering);
return;
}
else
{
std::vector<std::string> meshNames=GetMeshNames(fileName);
if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
- MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,false);
+ MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,false,isRenumbering);
else
{
std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
}
}
-void MEDLoader::WriteUMeshes(const char *fileName, const char *meshNameC, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
+void MEDLoader::WriteUMeshes(const char *fileName, const char *meshNameC, const std::vector<ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
{
std::string meshName(meshNameC);
if(meshName.empty())
}
}
-void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
+void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
{
int status=MEDLoaderBase::getStatusOfFile(fileName);
if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
}
}
-void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
+void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
{
f->checkCoherency();
int status=MEDLoaderBase::getStatusOfFile(fileName);
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingMemArray.hxx"
+#include <cmath>
+
using namespace ParaMEDMEM;
void MEDLoaderTest::testMesh1DRW()
//
MEDCouplingUMesh *mesh5=MEDLoader::ReadUMeshFromFile(fileName,mnane);
mesh1->setName(mnane);
- const int part3[18]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
+ const int part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true);
mesh6->setName(mnane);
mesh5->decrRef();
CPPUNIT_ASSERT(s=="azertty");
}
+void MEDLoaderTest::testMesh3DSurfShuffleRW()
+{
+ const char fileName[]="file15.med";
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ const int renumber1[6]={2,5,1,0,3,4};
+ mesh->renumberCells(renumber1,false);
+ mesh->checkCoherency();
+ MEDLoader::WriteUMesh(fileName,mesh,true);
+ MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName(),0);
+ CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
+ mesh_rw->decrRef();
+ mesh->decrRef();
+}
+
+void MEDLoaderTest::testFieldShuffleRW1()
+{
+ const char fileName[]="file16.med";
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setName("FieldOnCellsShuffle");
+ f1->setMesh(mesh);
+ DataArrayDouble *array=DataArrayDouble::New();
+ array->alloc(6,2);
+ f1->setArray(array);
+ array->decrRef();
+ double *tmp=array->getPointer();
+ const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
+ std::copy(arr1,arr1+12,tmp);
+ f1->setTime(3.14,2,7);
+ f1->checkCoherency();
+ //
+ const int renumber1[6]={2,1,5,0,3,4};
+ f1->renumberCells(renumber1,false);
+ MEDLoader::WriteField(fileName,f1,true);
+ MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldDoubleCell(fileName,mesh->getName(),0,f1->getName(),2,7);
+ CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
+ f2->decrRef();
+ //
+ mesh->decrRef();
+ f1->decrRef();
+}
+
+void MEDLoaderTest::testMultiFieldShuffleRW1()
+{
+ const char fileName[]="file17.med";
+ MEDCouplingUMesh *m=build3DMesh_2();
+ CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes());
+ const int polys[3]={1,4,6};
+ std::vector<int> poly2(polys,polys+3);
+ m->convertToPolyTypes(poly2);
+ const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11};
+ m->renumberCells(renum,false);
+ m->orientCorrectlyPolyhedrons();
+ // Writing
+ MEDLoader::WriteUMesh(fileName,m,true);
+ MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false);
+ MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false);
+ f1Tmp->decrRef();
+ f1->setTime(0.,1,2);
+ MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true);
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1->applyFunc("2*x");
+ f1->setTime(0.01,3,4);
+ MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true);
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1->applyFunc("2*x/3");
+ f1->setTime(0.02,5,6);
+ MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true);
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1->decrRef();
+ // Reading
+ std::vector<std::pair<int,int> > its;
+ its.push_back(std::pair<int,int>(1,2));
+ its.push_back(std::pair<int,int>(3,4));
+ its.push_back(std::pair<int,int>(5,6));
+ std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsDoubleOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName(),0,f_1->getName(),its);
+ CPPUNIT_ASSERT_EQUAL(3,(int)fs.size());
+ const MEDCouplingMesh *mm=fs[0]->getMesh();
+ CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12));
+ CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12));
+ CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12));
+ CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test
+ CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test
+ for(std::vector<MEDCouplingFieldDouble *>::iterator iter=fs.begin();iter!=fs.end();iter++)
+ (*iter)->decrRef();
+ //
+ f_1->decrRef();
+ f_2->decrRef();
+ f_3->decrRef();
+ //
+ m->decrRef();
+}
+
MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
{
double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2()
{
- double targetCoords[24]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
+ double targetCoords[24]={
+ -0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
+ -0.05,0.95, 0.2,1.2, 0.45,0.95
+ };
int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
targetMesh->setMeshDimension(2);
MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1()
{
- double targetCoords[36]={-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3 };
+ double targetCoords[36]={
+ -0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
+ ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3
+ };
int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4};
MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
targetMesh->setMeshDimension(2);
return ret;
}
+MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2()
+{
+ MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1();
+ int numbers[5]={0,1,3,4,5};
+ MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false);
+ m3dsurfBase->decrRef();
+ MEDCouplingUMesh *m1dBase=build1DMesh_1();
+ int numbers2[4]={0,1,2,3};
+ MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false);
+ m1dBase->decrRef();
+ m1d->changeSpaceDimension(3);
+ const double vec[3]={0.,1.,0.};
+ const double pt[3]={0.,0.,0.};
+ m1d->rotate(pt,vec,-M_PI/2.);
+ MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMeshFromThis(m1d,0);
+ m1d->decrRef();
+ m3dsurf->decrRef();
+ return ret;
+}
+
MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1()
{
MEDCouplingUMesh *mesh=build3DSurfMesh_1();
m->decrRef();
return f;
}
+