#include "MEDCouplingPartDefinition.hxx"
#include "MEDCouplingCartesianAMRMesh.hxx"
+#include <memory>
+
+auto PyDeleter = [](PyObject *ob) { Py_DECREF(ob) ; };
+
+class AutoPyPtr : std::unique_ptr<PyObject,decltype(PyDeleter)>
+{
+ public:
+ AutoPyPtr(PyObject *ob):std::unique_ptr<PyObject,decltype(PyDeleter)>(ob,PyDeleter) { }
+ PyObject *retn() { return this->release(); }
+ operator PyObject *() const { return this->get(); }
+};
+
+AutoPyPtr convertMapStringInt(const std::map<std::string,mcIdType>& cpp)
+{
+ AutoPyPtr ret(PyDict_New());
+ for(auto it : cpp)
+ {
+ AutoPyPtr st(PyString_FromString(it.first.c_str()));
+ AutoPyPtr val(PyInt_FromLong(it.second));
+ PyDict_SetItem(ret,st,val);
+ }
+ return ret;
+}
+
+AutoPyPtr convertMapStringVectString(const std::map<std::string,std::vector<std::string>>& cpp)
+{
+ AutoPyPtr ret(PyDict_New());
+ for(auto it : cpp)
+ {
+ AutoPyPtr st(PyString_FromString(it.first.c_str()));
+ AutoPyPtr vec(PyList_New(it.second.size()));
+ std::size_t itc(0);
+ for(auto it2 : it.second)
+ {
+ AutoPyPtr st2(PyString_FromString(it2.c_str()));
+ PyList_SetItem(vec,itc++,st2.retn());
+ }
+ PyDict_SetItem(ret,st,vec.retn());
+ }
+ return ret;
+}
+
static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
{
PyObject *ret=0;
#include <numeric>
#include <iterator>
#include <algorithm>
-
+#include <memory>
med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
MED_SEG2,
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
+// see reference : https://en.cppreference.com/w/cpp/iterator/iterator
+class MEDVectorStringIterator : public std::iterator< std::input_iterator_tag, long, long, const std::string*, std::string >
+{
+ long _num = 0;
+ char *_data = nullptr;
+public:
+ explicit MEDVectorStringIterator(long num , char *data) : _num(num),_data(data) {}
+ MEDVectorStringIterator& operator++() { ++_num; return *this;}
+ bool operator==(const MEDVectorStringIterator& other) const {return _num == other._num;}
+ bool operator!=(const MEDVectorStringIterator& other) const {return !(*this == other);}
+ reference operator*() const {return MEDLoaderBase::buildStringFromFortran(_data+_num*MED_LNAME_SIZE,MED_LNAME_SIZE);}
+};
+
+void MEDCoupling::GetFamiliesGroupsInfo(const std::string& fileName, const std::string& meshName, std::map<std::string,mcIdType>& families, std::map<std::string,std::vector<std::string>>& groupsOnFam)
+{
+ MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
+ med_int nbFams(MEDnFamily(fid,meshName.c_str()));
+ char nomfam[MED_NAME_SIZE+1];
+ for(med_int i=0;i<nbFams;++i)
+ {
+ med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),i+1)),famId;
+ std::unique_ptr<char[]> gro{new char[MED_LNAME_SIZE*nbGrps+1]};
+ MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get()));
+ std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
+ families[fam] = FromMedInt<mcIdType>(famId);
+ std::vector<std::string> v(nbGrps);
+ std::copy(MEDVectorStringIterator(0,gro.get()),MEDVectorStringIterator(nbGrps,gro.get()),v.begin());
+ groupsOnFam[fam] = v;
+ }
+}
+
std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
{
std::vector<std::string> ret;
//
// Author : Anthony Geay (CEA/DEN)
-#ifndef __MEDLOADER_HXX__
-#define __MEDLOADER_HXX__
+#pragma once
#include "MEDLoaderDefines.hxx"
#include "InterpKernelException.hxx"
MEDLOADER_EXPORT std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, mcIdType& numberOfNodes);
MEDLOADER_EXPORT std::vector< std::pair<std::string,std::string> > GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName);
MEDLOADER_EXPORT std::vector<std::string> GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName);
+ MEDLOADER_EXPORT void GetFamiliesGroupsInfo(const std::string& fileName, const std::string& meshName, std::map<std::string,mcIdType>& families, std::map<std::string,std::vector<std::string>>& groupsOnFam);
MEDLOADER_EXPORT std::vector<std::string> GetMeshGroupsNames(const std::string& fileName, const std::string& meshName);
MEDLOADER_EXPORT std::vector<std::string> GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName);
MEDLOADER_EXPORT std::vector<std::string> GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName);
MEDLOADER_EXPORT void AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj);
}
-#endif
#include "MEDFileEntities.hxx"
#include "MEDFileMeshReadSelector.hxx"
#include "MEDFileFieldOverView.hxx"
+#include "MEDCouplingTypemaps.i"
#include "MEDLoaderTypemaps.i"
#include "SauvReader.hxx"
#include "SauvWriter.hxx"
%rename (ReadUMeshFromGroups) ReadUMeshFromGroupsSwig;
%rename (ReadUMeshFromFamilies) ReadUMeshFromFamiliesSwig;
%rename (ReadField) ReadFieldSwig;
+%rename (GetFamiliesGroupsInfo) GetFamiliesGroupsInfoSwig;
%inline
{
return 8*sizeof(med_int);
}
+ PyObject *GetFamiliesGroupsInfoSwig(const std::string& fileName, const std::string& meshName)
+ {
+ std::map<std::string,mcIdType> families;
+ std::map<std::string,std::vector<std::string>> groupsOnFam;
+ MEDCoupling::GetFamiliesGroupsInfo(fileName,meshName,families,groupsOnFam);
+ AutoPyPtr a(convertMapStringInt(families)),b(convertMapStringVectString(groupsOnFam));
+ AutoPyPtr ret(PyTuple_New(2));
+ PyTuple_SetItem(ret,0,a.retn());
+ PyTuple_SetItem(ret,1,b.retn());
+ return ret.retn();
+ }
+
MEDCoupling::MEDCouplingField *ReadFieldSwig(const std::string& fileName)
{
MCAuto<MEDCoupling::MEDCouplingField> ret(MEDCoupling::ReadField(fileName));