return (*it).second;
}
+std::vector<int> MEDFileUMesh::getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> famIds;
+ for(std::vector<std::string>::const_iterator it=famNames.begin();it!=famNames.end();it++)
+ {
+ std::map<std::string,int>::const_iterator it2=_families.find(*it);
+ if(it2==_families.end())
+ {
+ std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ famIds.push_back((*it2).second);
+ }
+ return famIds;
+}
+
+std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
+{
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ if((*it).second==id)
+ return (*it).first;
+ std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
int MEDFileUMesh::getMeshDimension() const
{
int lev=0;
MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
{
- std::vector<int> famIds;
- for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++)
- {
- std::map<std::string,int>::const_iterator it2=_families.find(*it);
- if(it2==_families.end())
- {
- std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- famIds.push_back((*it2).second);
- }
+ std::vector<int> famIds=getFamiliesIds(fams);
const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax);
return l1->getFamilyPart(famIds);
}
DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMax, const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
{
- std::vector<int> famIds;
- for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++)
- {
- std::map<std::string,int>::const_iterator it2=_families.find(*it);
- if(it2==_families.end())
- {
- std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- famIds.push_back((*it2).second);
- }
+ std::vector<int> famIds=getFamiliesIds(fams);
const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax);
return l1->getFamilyPartArr(famIds);
}
DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
{
- return 0;
+ std::vector<int> famIds=getFamiliesIds(fams);
+ DataArrayInt *da=_fam_coords->getIdsEqualList(famIds);
+ return MEDFileUMeshSplitL1::renumber(_num_coords,da);
}
MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
int getNumberOfLevels() const { return _ms.size(); }
int getNumberOfNonEmptyLevels() const;
int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
+ std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
int getMeshDimension() const;
std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
std::vector<std::string> getGroupsNames() const;
return m;
}
-DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const
+DataArrayInt *MEDFileUMeshSplitL1::renumber(const DataArrayInt *renum, DataArrayInt *da)
{
- if((const DataArrayInt *)_num==0)
+ if((const DataArrayInt *)renum==0)
return da;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=_num->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
da->decrRef();
locnum->incrRef();
return locnum;
}
+DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const
+{
+ return renumber(_num,da);
+}
+
std::vector<int> MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
{
int id=-1;
static std::vector<int> getNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
static void traduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
+ static DataArrayInt *renumber(const DataArrayInt *renum, DataArrayInt *da);
private:
MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
DataArrayInt *renumIfNeededArr(DataArrayInt *da) const;
PyList_SetItem(ret,i,PyInt_FromLong((int)v[i]));
return ret;
}
+ static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<std::string> grps;
+ converPyListToVecString(li,grps);
+ return MEDLoader::ReadUMeshFromGroups(fileName,meshName,meshDimRelToMax,grps);
+ }
+ static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<std::string> fams;
+ converPyListToVecString(li,fams);
+ return MEDLoader::ReadUMeshFromFamilies(fileName,meshName,meshDimRelToMax,fams);
+ }
}
- static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception);
- static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingFieldDouble *ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
grps.index("mesh4");
grps.index("3DMesh_1");
#
- vec=["mesh2"];
+ vec=("mesh2",);
mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
vec=["mesh3"];
vec=["mesh4"];
mesh4_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
self.assertTrue(mesh4_2.isEqual(mesh4,1e-12));
- vec=["3DMesh_1"];
+ vec="3DMesh_1";
mesh1_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
mesh1.setName("3DMesh_1");
self.assertTrue(mesh1_2.isEqual(mesh1,1e-12));
self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2").getValues());
self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"]).getValues());
self.assertEqual([2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3"]).getValues());
+ famn=medmesh.getFamilyNameGivenId(0)
+ self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn).getValues());
+ # without renum
+
pass
pass
return ret;
}
+static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
+{
+ if(PyList_Check(pyLi))
+ {
+ int size=PyList_Size(pyLi);
+ v.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyList_GetItem(pyLi,i);
+ if(!PyString_Check(o))
+ throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
+ const char *st=PyString_AsString(o);
+ v[i]=std::string(st);
+ }
+ }
+ else if(PyTuple_Check(pyLi))
+ {
+ int size=PyTuple_Size(pyLi);
+ v.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyTuple_GetItem(pyLi,i);
+ if(!PyString_Check(o))
+ throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
+ const char *st=PyString_AsString(o);
+ v[i]=std::string(st);
+ }
+ }
+ else if(PyString_Check(pyLi))
+ {
+ v.resize(1);
+ v[0]=std::string((const char *)PyString_AsString(pyLi));
+ }
+ else
+ {
+ throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
+ }
+}
+
static PyObject *convertFieldDoubleVecToPy(const std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>& li)
{
int sz=li.size();