]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Low level method to have access of arrays by type.
authorageay <ageay>
Thu, 25 Aug 2011 08:18:29 +0000 (08:18 +0000)
committerageay <ageay>
Thu, 25 Aug 2011 08:18:29 +0000 (08:18 +0000)
src/MEDLoader/MEDFileField.cxx
src/MEDLoader/MEDFileField.hxx
src/MEDLoader/Swig/MEDLoader.i

index 03b1d21fe2653cf29240421231e615132a0604c5..64ac48e871dc3efa4b909f126800b91a5e18ca6f 100644 (file)
@@ -378,6 +378,14 @@ void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_
                              reinterpret_cast<const unsigned char*>(_arr->getConstPointer()));
 }
 
+void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, const DataArrayDouble *& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
+{
+  type=_type;
+  pfl=_profile;
+  loc=_localization;
+  dad=_arr;
+}
+
 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
 {
   switch(type)
@@ -611,6 +619,16 @@ void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>
     }
 }
 
+void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector<const DataArrayDouble *>& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
+{
+  int sz=_field_pm_pt_pd.size();
+  dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
+  for(int i=0;i<sz;i++)
+    {
+      _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
+    }
+}
+
 int MEDFileFieldPerMeshPerType::getIteration() const
 {
   return _father->getIteration();
@@ -872,6 +890,19 @@ void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types
     (*it)->fillTypesOfFieldAvailable(types);
 }
 
+std::vector< std::vector<const DataArrayDouble *> > MEDFileFieldPerMesh::getFieldSplitedByType(std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> > & locs) const throw(INTERP_KERNEL::Exception)
+{
+  int sz=_field_pm_pt.size();
+  std::vector< std::vector<const DataArrayDouble *> > ret(sz);
+  types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
+  for(int i=0;i<sz;i++)
+    {
+      types[i]=_field_pm_pt[i]->getGeoType();
+      _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
+    }
+  return ret;
+}
+
 double MEDFileFieldPerMesh::getTime() const
 {
   return _father->getTime();
@@ -1737,6 +1768,20 @@ std::vector<TypeOfField> MEDFileField1TSWithoutDAS::getTypesOfFieldAvailable() c
   return ret;
 }
 
+/*!
+ * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
+ */
+std::vector< std::vector<const DataArrayDouble *> > MEDFileField1TSWithoutDAS::getFieldSplitedByType(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
+{
+  int meshId=0;
+  if(mname)
+    meshId=getMeshIdFromMeshName(mname);
+  else
+    if(_field_per_mesh.empty())
+      throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::getFieldSplitedByType : This is empty !");
+  return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
+}
+
 void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
 {
   med_int numdt,numit;
@@ -2377,6 +2422,11 @@ std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTSWithoutDAS::getTypesO
   return ret;
 }
 
+std::vector< std::vector<const DataArrayDouble *> > MEDFileFieldMultiTSWithoutDAS::getFieldSplitedByType(int iteration, int order, const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
+{
+  return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
+}
+
 const MEDFileField1TSWithoutDAS& MEDFileFieldMultiTSWithoutDAS::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
 {
   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
index 2c9a2cba3f179ccfe17dbe2b1e625eeb81ee8d54..8909fc53c9afad542f4044f547832c0af7cfaae4 100644 (file)
@@ -85,6 +85,7 @@ namespace ParaMEDMEM
     void assignFieldProfile(const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
     void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
     void assignNodeFieldProfile(const char *pflName, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
+    void getCoarseData(TypeOfField& type, const DataArrayDouble *& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception);
     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
     const MEDFileFieldPerMeshPerType *getFather() const;
     int getIteration() const;
@@ -134,6 +135,7 @@ namespace ParaMEDMEM
     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
     void getDimension(int& dim) const;
     void fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception);
+    void fillFieldSplitedByType(std::vector<const DataArrayDouble *>& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception);
     int getIteration() const;
     int getOrder() const;
     double getTime() const;
@@ -172,6 +174,7 @@ namespace ParaMEDMEM
     void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
     void fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception);
+    std::vector< std::vector<const DataArrayDouble *> > getFieldSplitedByType(std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception);
     void getDimension(int& dim) const;
     double getTime() const;
     int getIteration() const;
@@ -310,6 +313,7 @@ namespace ParaMEDMEM
     void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
   public:
     std::vector<TypeOfField> getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception);
+    std::vector< std::vector<const DataArrayDouble *> > getFieldSplitedByType(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception);
@@ -364,6 +368,7 @@ namespace ParaMEDMEM
     int getNumberOfTS() const;
     std::vector< std::pair<int,int> > getIterations() const;
     std::vector< std::vector<TypeOfField> > getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception);
+    std::vector< std::vector<const DataArrayDouble *> > getFieldSplitedByType(int iteration, int order, const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception);
     void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
     std::string getName() const;
     std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception);
index e7733e2174c01a53937afd6e92cad4e2c970b5af..98bfc961fe5baf24ba635a3ca8bfa809080ddcbc 100644 (file)
@@ -572,10 +572,46 @@ namespace ParaMEDMEM
          {
            std::vector<TypeOfField> ret=self->getTypesOfFieldAvailable();
            PyObject *ret2=PyList_New(ret.size());
-           for(int i=0;i<ret.size();i++)
+           for(int i=0;i<(int)ret.size();i++)
              PyList_SetItem(ret2,i,SWIG_From_int(ret[i]));
            return ret2;
          }
+
+         PyObject *getFieldSplitedByType(const char *mname=0) const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<INTERP_KERNEL::NormalizedCellType> types;
+           std::vector< std::vector<TypeOfField> > typesF;
+           std::vector< std::vector<std::string> > pfls;
+           std::vector< std::vector<std::string> > locs;
+           std::vector< std::vector<const DataArrayDouble *> > ret=self->getFieldSplitedByType(mname,types,typesF,pfls,locs);
+           int sz=ret.size();
+           PyObject *ret2=PyList_New(sz);
+           for(int i=0;i<sz;i++)
+             {
+               const std::vector<const DataArrayDouble *>& dadsI=ret[i];
+               const std::vector<TypeOfField>& typesFI=typesF[i];
+               const std::vector<std::string>& pflsI=pfls[i];
+               const std::vector<std::string>& locsI=locs[i];
+               PyObject *elt=PyTuple_New(2);
+               PyTuple_SetItem(elt,0,SWIG_From_int(types[i]));
+               int sz2=ret[i].size();
+               PyObject *elt2=PyList_New(sz2);
+               for(int j=0;j<sz2;j++)
+                 {
+                   PyObject *elt3=PyTuple_New(4);
+                   if(dadsI[j])
+                     dadsI[j]->incrRef();
+                   PyTuple_SetItem(elt3,0,SWIG_From_int(typesFI[j]));
+                   PyTuple_SetItem(elt3,1,SWIG_NewPointerObj(SWIG_as_voidptr(dadsI[j]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+                   PyTuple_SetItem(elt3,2,PyString_FromString(pflsI[j].c_str()));
+                   PyTuple_SetItem(elt3,3,PyString_FromString(locsI[j].c_str()));
+                   PyList_SetItem(elt2,j,elt3);
+                 }
+               PyTuple_SetItem(elt,1,elt2);
+               PyList_SetItem(ret2,i,elt);
+             }
+           return ret2;
+         }
        }
   };
 
@@ -651,16 +687,52 @@ namespace ParaMEDMEM
          {
            std::vector< std::vector<TypeOfField> > ret=self->getTypesOfFieldAvailable();
            PyObject *ret2=PyList_New(ret.size());
-           for(int i=0;i<ret.size();i++)
+           for(int i=0;i<(int)ret.size();i++)
              {
                const std::vector<TypeOfField>& rett=ret[i];
                PyObject *ret3=PyList_New(rett.size());
-               for(int j=0;j<rett.size();j++)
+               for(int j=0;j<(int)rett.size();j++)
                  PyList_SetItem(ret3,j,SWIG_From_int(rett[j]));
                PyList_SetItem(ret2,i,ret3);
              }
            return ret2;
          }
+
+         PyObject *getFieldSplitedByType(int iteration, int order, const char *mname=0) const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<INTERP_KERNEL::NormalizedCellType> types;
+           std::vector< std::vector<TypeOfField> > typesF;
+           std::vector< std::vector<std::string> > pfls;
+           std::vector< std::vector<std::string> > locs;
+           std::vector< std::vector<const DataArrayDouble *> > ret=self->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
+           int sz=ret.size();
+           PyObject *ret2=PyList_New(sz);
+           for(int i=0;i<sz;i++)
+             {
+               const std::vector<const DataArrayDouble *>& dadsI=ret[i];
+               const std::vector<TypeOfField>& typesFI=typesF[i];
+               const std::vector<std::string>& pflsI=pfls[i];
+               const std::vector<std::string>& locsI=locs[i];
+               PyObject *elt=PyTuple_New(2);
+               PyTuple_SetItem(elt,0,SWIG_From_int(types[i]));
+               int sz2=ret[i].size();
+               PyObject *elt2=PyList_New(sz2);
+               for(int j=0;j<sz2;j++)
+                 {
+                   PyObject *elt3=PyTuple_New(4);
+                   if(dadsI[j])
+                     dadsI[j]->incrRef();
+                   PyTuple_SetItem(elt3,0,SWIG_From_int(typesFI[j]));
+                   PyTuple_SetItem(elt3,1,SWIG_NewPointerObj(SWIG_as_voidptr(dadsI[j]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+                   PyTuple_SetItem(elt3,2,PyString_FromString(pflsI[j].c_str()));
+                   PyTuple_SetItem(elt3,3,PyString_FromString(locsI[j].c_str()));
+                   PyList_SetItem(elt2,j,elt3);
+                 }
+               PyTuple_SetItem(elt,1,elt2);
+               PyList_SetItem(ret2,i,elt);
+             }
+           return ret2;
+         }
        }
   };