void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret)
{
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::AppendFieldFromMeshes : internal error ! NULL ret !");
for(int i=0;i<ms->getNumberOfMeshes();i++)
{
MEDFileMesh *mm(ms->getMeshAtPos(i));
arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
arr->iota();
f->setArray(arr);
- f->setName(mm->getName());
+ f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
f1tsMultiLev->setFieldNoProfileSBT(f);
}
}
ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(m->getNumberOfNodes());
arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
arr->iota(); f->setArray(arr);
- f->setName(mm->getName());
+ f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
f1tsMultiLev->setFieldNoProfileSBT(f);
}
else
arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
arr->iota();
f->setArray(arr);
- f->setName(mm->getName());
+ f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
f1tsMultiLev->setFieldNoProfileSBT(f);
}
//
}
}
+std::string MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret)
+{
+ static const char KEY_STR_TO_AVOID_COLLIDE[]="MESH@";
+ if(!ret)
+ throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh : internal error ! NULL ret !");
+ std::vector<std::string> fieldNamesAlreadyExisting(ret->getFieldsNames());
+ if(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),meshName)==fieldNamesAlreadyExisting.end())
+ return meshName;
+ std::string tmpName(KEY_STR_TO_AVOID_COLLIDE); tmpName+=meshName;
+ while(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),tmpName)!=fieldNamesAlreadyExisting.end())
+ tmpName=std::string(KEY_STR_TO_AVOID_COLLIDE)+tmpName;
+ return tmpName;
+}
+
ParaMEDMEM::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms)
{
ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFields> ret(ParaMEDMEM::MEDFileFields::New());
const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms);
static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret);
+ static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret);
static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
private:
// 1st : timesteps, 2nd : meshName, 3rd : common support