]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Target MEDReader
authorageay <ageay>
Tue, 23 Jul 2013 16:02:36 +0000 (16:02 +0000)
committerageay <ageay>
Tue, 23 Jul 2013 16:02:36 +0000 (16:02 +0000)
src/MEDLoader/MEDFileFieldOverView.cxx
src/MEDLoader/MEDFileFieldOverView.hxx

index 7d43b18a7cb3a2748b95dcece291c2d81f2eaf40..98fbbf48ce44f4e76fd30714a493cc8ee0b7803d 100644 (file)
@@ -885,6 +885,12 @@ MEDMeshMultiLev::MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCell
     }
 }
 
+MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction)
+{
+}
+
+//=
+
 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
 {
   return new MEDUMeshMultiLev(m,levs);
@@ -938,18 +944,88 @@ void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INT
 {
    if(!pflNodes || !pflNodes->isAllocated())
      return ;
-   /*std::vector<int> ngs(getNodeGridStructure());
+   std::size_t sz(_parts.size());
+   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
+   std::vector< const DataArrayInt *> aa(sz);
+   for(std::size_t i=0;i<sz;i++)
+     {
+       
+       const DataArrayInt *pfl(_pfls[i]);
+       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
+       if(pfl)
+         m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
+       DataArrayInt *cellIds=0;
+       m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
+       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
+       MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
+       int tmp=-1;
+       a[i]=m2->getNodeIdsInUse(tmp); aa[i]=a[i];
+       if(pfl)
+         _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
+       else
+         _pfls[i]=cellIdsSafe;
+     }
+   _node_reduction=DataArrayInt::Aggregate(aa);
+   _node_reduction->sort(true);
+   _node_reduction=_node_reduction->buildUnique();
+}
+
+MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
+{
+  return new MEDUMeshMultiLev(*this);
+}
+
+MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
+{
+}
+
+MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
+{
+  _parts.resize(1);
+  _parts[0]=part;
+}
+
+//=
+
+MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
+{
+}
+
+MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
+{
+}
+
+void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
+{
+  if(!pflNodes || !pflNodes->isAllocated())
+    return ;
+  std::vector<int> ngs(getNodeGridStructure());
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",GMEDCouplingStructuredMesh::etGeoTypeGivenMeshDimension(ngs.size())));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
   m->setNodalConnectivity(conn);
+  const DataArrayInt *pfl(_pfls[0]);
+  if(pfl)
+    {
+      m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
+    }
   DataArrayInt *cellIds=0;
   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
   int tmp=-1;
-  _node_reduction=m2->getNodeIdsInUse(tmp);*/
+  _node_reduction=m2->getNodeIdsInUse(tmp);
+  if(pfl)
+    _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
+  else
+    _pfls[0]=cellIdsSafe;
 }
 
+MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
+{
+}
+
+//=
+
 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
 {
   return new MEDCMeshMultiLev(m,levs);
@@ -996,6 +1072,10 @@ MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTE
     }
 }
 
+MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other)
+{
+}
+
 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
 {
   std::vector<int> ret(_coords.size());
@@ -1004,6 +1084,51 @@ std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const throw(INTERP_KER
   return ret;
 }
 
+MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
+{
+  const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
+  std::vector<int> cgs,ngs(getNodeGridStructure());
+  cgs.resize(ngs.size());
+  std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
+  if(pfl)
+    {
+      std::vector< std::pair<int,int> > cellParts;
+      if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
+        {
+          MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
+          if(nr)
+            { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+          ret->_nb_entities[0]=pfl->getNumberOfTuples();
+          ret->_pfls[0]=0;
+          std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
+          for(std::size_t i=0;i<_coords.size();i++)
+            coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
+          ret->_coords=coords;
+          return ret.retn();
+        }
+      else
+        {
+          MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
+          for(std::size_t i=0;i<ngs.size();i++)
+            m->setCoordsAt(i,_coords[i]);
+          MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
+          MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
+          MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
+          if(nr)
+            { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+          return ret.retn();
+        }
+    }
+  else
+    {
+      MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
+      if(nr)
+        { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+      return ret.retn();
+    }
+}
+
 //=
 
 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
@@ -1047,33 +1172,61 @@ MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearM
   _structure=m->getMesh()->getNodeGridStructure();
 }
 
-std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
+MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
 {
-  return _structure;
 }
 
-//=
-
-MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
-{
-}
-
-MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
+std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
 {
+  return _structure;
 }
 
-void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
+MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
 {
-  if(!pflNodes || !pflNodes->isAllocated())
-    return ;
-  std::vector<int> ngs(getNodeGridStructure());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
-  m->setNodalConnectivity(conn);
-  DataArrayInt *cellIds=0;
-  m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
-  int tmp=-1;
-  _node_reduction=m2->getNodeIdsInUse(tmp);
+  const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
+  std::vector<int> cgs,ngs(getNodeGridStructure());
+  cgs.resize(ngs.size());
+  std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
+  if(pfl)
+    {
+      std::vector< std::pair<int,int> > cellParts,nodeParts;
+      if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
+        {
+          nodeParts=cellParts;
+          std::vector<int> st(ngs.size());
+          for(std::size_t i=0;i<ngs.size();i++)
+            {
+              nodeParts[i].second++;
+              st[i]=nodeParts[i].second-nodeParts[i].first;
+            }
+          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
+          MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
+          if(nr)
+            { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+          ret->_nb_entities[0]=pfl->getNumberOfTuples();
+          ret->_pfls[0]=0;
+          ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
+          ret->_structure=st;
+          return ret.retn();
+        }
+      else
+        {
+          MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
+          m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
+          MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
+          MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
+          MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
+          if(nr)
+            { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+          return ret.retn();
+        }
+    }
+  else
+    {
+      MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
+      if(nr)
+        { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
+      return ret.retn();
+    }
 }
index 6dca9aa9df7b41d7d0930c741994012a740ea1a0..e8866b543ba4437c75bbb3b73626981284beaa04 100644 (file)
@@ -73,23 +73,30 @@ namespace ParaMEDMEM
     static MEDMeshMultiLev *NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode) throw(INTERP_KERNEL::Exception);
     void setNodeReduction(const DataArrayInt *nr);
     virtual void selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception) = 0;
+    virtual MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception) = 0;
   protected:
     MEDMeshMultiLev();
+    MEDMeshMultiLev(const MEDMeshMultiLev& other);
     MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
-    protected:
+  protected:
     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _pfls;
     std::vector< INTERP_KERNEL::NormalizedCellType > _geo_types;
     std::vector<int> _nb_entities;
     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _node_reduction;
   };
-
+  
+  class MEDStructuredMeshMultiLev;
+  
   class MEDUMeshMultiLev : public MEDMeshMultiLev
   {
   public:
     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
     static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
     void selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception);
+    MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
+    MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part);
   private:
+    MEDUMeshMultiLev(const MEDUMeshMultiLev& other);
     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs);
     MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
   private:
@@ -103,6 +110,7 @@ namespace ParaMEDMEM
     virtual std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception) = 0;
   protected:
     MEDStructuredMeshMultiLev();
+    MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other);
     MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
   };
   
@@ -112,7 +120,9 @@ namespace ParaMEDMEM
     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
     static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
     std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
+    MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
   private:
+    MEDCMeshMultiLev(const MEDCMeshMultiLev& other);
     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs);
     MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
   private:
@@ -125,7 +135,9 @@ namespace ParaMEDMEM
     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception);
     static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls , const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception);
     std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
+    MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception);
   private:
+    MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other);
     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs);
     MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities);
   private: