Salome HOME
Merge remote branch 'origin/master'
[modules/paravis.git] / src / Plugins / MEDReader / IO / MEDFileFieldRepresentationTree.cxx
index 0721775a5ee12fab90ae0c97063c2e62e1e1541d..b3512390494ebdf34402d64cd8e12af539acb7d1 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2010-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "MEDFileData.hxx"
 #include "SauvReader.hxx"
 
+#ifdef MEDREADER_USE_MPI
+  #include "ParaMEDFileMesh.hxx"
+#endif
+
 #include "vtkXMLUnstructuredGridWriter.h"//
 
 #include "vtkUnstructuredGrid.h"
@@ -234,12 +238,15 @@ std::string MEDFileFieldRepresentationLeavesArrays::getZeName() const
   return _ze_full_name;
 }
 
-void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const
+const char *MEDFileFieldRepresentationLeavesArrays::getZeNameC() const
+{
+  return _ze_full_name.c_str();
+}
+
+void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const
 {
   vtkIdType refId(sil->AddChild(root,edge));
   names.push_back(_ze_name);
-  std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name;
-  _ze_full_name=oss3.str();
   //
   if(MEDFileFieldRepresentationTree::IsFieldMeshRegardingInfo(((operator->())->getInfo())))
     {
@@ -248,6 +255,12 @@ void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* si
     }
 }
 
+void MEDFileFieldRepresentationLeavesArrays::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const
+{
+  std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name;
+  _ze_full_name=oss3.str();
+}
+
 bool MEDFileFieldRepresentationLeavesArrays::getStatus() const
 {
   return _activated;
@@ -469,15 +482,21 @@ int MEDFileFieldRepresentationLeaves::getNumberOfTS() const
   return _arrays[0]->getNumberOfTS();
 }
 
+void MEDFileFieldRepresentationLeaves::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const
+{
+  for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
+    (*it).computeFullNameInLeaves(tsName,meshName,comSupStr);
+}
+
 /*!
  * \param [in] ms is the meshes pointer. It can be used only for information of geometric types. No special processing will be requested on ms.
  */
-void MEDFileFieldRepresentationLeaves::feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const
+void MEDFileFieldRepresentationLeaves::feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const
 {
   vtkIdType root2(sil->AddChild(root,edge));
   names.push_back(std::string("Arrs"));
   for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
-    (*it).feedSIL(sil,root2,edge,tsName,meshName,comSupStr,names);
+    (*it).feedSIL(sil,root2,edge,names);
   //
   vtkIdType root3(sil->AddChild(root,edge));
   names.push_back(std::string("InfoOnGeoType"));
@@ -516,6 +535,12 @@ bool MEDFileFieldRepresentationLeaves::containZeName(const char *name, int& id)
   return false;
 }
 
+void MEDFileFieldRepresentationLeaves::dumpState(std::map<std::string,bool>& status) const
+{
+  for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
+    status[(*it).getZeName()]=(*it).getStatus();
+}
+
 bool MEDFileFieldRepresentationLeaves::isActivated() const
 {
   for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
@@ -884,6 +909,28 @@ void MEDFileFieldRepresentationTree::assignIds() const
       for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
         (*it2).setId(zeId);
 }
+
+void MEDFileFieldRepresentationTree::computeFullNameInLeaves() const
+{
+   std::size_t it0Cnt(0);
+   for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++,it0Cnt++)
+     {
+       std::ostringstream oss; oss << MEDFileFieldRepresentationLeavesArrays::TS_STR << it0Cnt;
+       std::string tsName(oss.str());
+       for(std::vector< std::vector< MEDFileFieldRepresentationLeaves > >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+         {
+           std::string meshName((*it1)[0].getMeshName());
+           std::size_t it2Cnt(0);
+           for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++,it2Cnt++)
+             {
+               std::ostringstream oss2; oss2 << MEDFileFieldRepresentationLeavesArrays::COM_SUP_STR << it2Cnt;
+               std::string comSupStr(oss2.str());
+               (*it2).computeFullNameInLeaves(tsName,meshName,comSupStr);
+             }
+         }
+     }
+}
+
 void MEDFileFieldRepresentationTree::activateTheFirst() const
 {
   for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++)
@@ -938,7 +985,7 @@ void MEDFileFieldRepresentationTree::feedSIL(vtkMutableDirectedGraph* sil, vtkId
               std::string comSupStr(oss2.str());
               vtkIdType typeId2(sil->AddChild(typeId1,edge));
               names.push_back(comSupStr);
-              (*it2).feedSIL(_ms,sil,typeId2,edge,tsName,meshName,comSupStr,names);
+              (*it2).feedSIL(_ms,meshName,sil,typeId2,edge,names);
             } 
         }
     }
@@ -1006,6 +1053,12 @@ std::string MEDFileFieldRepresentationTree::getNameOf(int id) const
   return elt.getZeName();
 }
 
+const char *MEDFileFieldRepresentationTree::getNameOfC(int id) const
+{
+  const MEDFileFieldRepresentationLeavesArrays& elt(getLeafArr(id));
+  return elt.getZeNameC();
+}
+
 bool MEDFileFieldRepresentationTree::getStatusOf(int id) const
 {
   const MEDFileFieldRepresentationLeavesArrays& elt(getLeafArr(id));
@@ -1020,7 +1073,8 @@ int MEDFileFieldRepresentationTree::getIdHavingZeName(const char *name) const
       for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
         if((*it2).containZeName(name,ret))
           return ret;
-  throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::getIdHavingZeName : No such a name !");
+  std::ostringstream msg; msg << "MEDFileFieldRepresentationTree::getIdHavingZeName : No such a name \"" << name << "\" !";
+  throw INTERP_KERNEL::Exception(msg.str().c_str());
 }
 
 bool MEDFileFieldRepresentationTree::changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const
@@ -1043,12 +1097,33 @@ int MEDFileFieldRepresentationTree::getMaxNumberOfTimeSteps() const
 /*!
  * 
  */
-void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv)
+void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts)
 {
   if(isMEDOrSauv)
     {
-      _ms=MEDFileMeshes::New(fileName);
-      _fields=MEDFileFields::New(fileName,false);//false is important to not read the values
+      if((iPart==-1 && nbOfParts==-1) || (iPart==0 && nbOfParts==1))
+        {
+          _ms=MEDFileMeshes::New(fileName);
+          _fields=MEDFileFields::New(fileName,false);//false is important to not read the values
+        }
+      else
+        {
+#ifdef MEDREADER_USE_MPI
+          _ms=ParaMEDFileMeshes::New(iPart,nbOfParts,fileName);
+          int nbMeshes(_ms->getNumberOfMeshes());
+          for(int i=0;i<nbMeshes;i++)
+            {
+              ParaMEDMEM::MEDFileMesh *tmp(_ms->getMeshAtPos(i));
+              ParaMEDMEM::MEDFileUMesh *tmp2(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(tmp));
+              if(tmp2)
+                MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3(tmp2->zipCoords());
+            }
+          _fields=MEDFileFields::LoadPartOf(fileName,false,_ms);//false is important to not read the values
+#else
+          std::ostringstream oss; oss << "MEDFileFieldRepresentationTree::loadMainStructureOfFile : request for iPart/nbOfParts=" << iPart << "/" << nbOfParts << " whereas Plugin not compiled with MPI !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+#endif
+        }
     }
   else
     {
@@ -1090,7 +1165,24 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
         {
           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> fmts((*fields)->getFieldAtPos((int)j));
           std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > tmp(fmts->splitDiscretizations());
-          allFMTSLeavesToDisplaySafe.insert(allFMTSLeavesToDisplaySafe.end(),tmp.begin(),tmp.end());
+          // EDF 8655
+          for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > >::const_iterator it=tmp.begin();it!=tmp.end();it++)
+            {
+              if(!(*it)->presenceOfMultiDiscPerGeoType())
+                allFMTSLeavesToDisplaySafe.push_back(*it);
+              else
+                {// The case of some parts of field have more than one discretization per geo type.
+                  std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > subTmp((*it)->splitMultiDiscrPerGeoTypes());
+                  std::size_t it0Cnt(0);
+                  for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > >::iterator it0=subTmp.begin();it0!=subTmp.end();it0++,it0Cnt++)//not const because setName
+                    {
+                      std::ostringstream oss; oss << (*it0)->getName() << "_" << std::setfill('M') << std::setw(3) << it0Cnt;
+                      (*it0)->setName(oss.str());
+                      allFMTSLeavesToDisplaySafe.push_back(*it0);
+                    }
+                }
+            }
+         // end EDF 8655
         }
     }
   std::vector< MEDFileAnyTypeFieldMultiTS *> allFMTSLeavesToDisplay(allFMTSLeavesToDisplaySafe.size());
@@ -1156,6 +1248,7 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
     }
   this->removeEmptyLeaves();
   this->assignIds();
+  this->computeFullNameInLeaves();
 }
 
 void MEDFileFieldRepresentationTree::removeEmptyLeaves()
@@ -1306,8 +1399,20 @@ void MEDFileFieldRepresentationTree::printMySelf(std::ostream& os) const
     os << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << std::endl;
 }
 
+std::map<std::string,bool> MEDFileFieldRepresentationTree::dumpState() const
+{
+  std::map<std::string,bool> ret;
+  for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++)
+    for(std::vector< std::vector< MEDFileFieldRepresentationLeaves > >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+      for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
+        (*it2).dumpState(ret);
+  return ret;
+}
+
 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));
@@ -1315,53 +1420,53 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
       ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileField1TS> f1tsMultiLev(ParaMEDMEM::MEDFileField1TS::New());
       MEDFileUMesh *mmu(dynamic_cast<MEDFileUMesh *>(mm));
       if(mmu)
-       {
-         for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
-           {
-             std::vector<INTERP_KERNEL::NormalizedCellType> gts(mmu->getGeoTypesAtLevel(*it));
-             for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator gt=gts.begin();gt!=gts.end();gt++)
-               {
-                 ParaMEDMEM::MEDCouplingMesh *m(mmu->getDirectUndergroundSingleGeoTypeMesh(*gt));
-                 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS));
-                 f->setMesh(m);
-                 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected());
-                 arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
-                 arr->iota();
-                 f->setArray(arr);
-                 f->setName(mm->getName());
-                 f1tsMultiLev->setFieldNoProfileSBT(f);
-               }
-           }
-         if(levs.empty())
-           {
-             std::vector<int> levsExt(mm->getNonEmptyLevelsExt());
-             if(levsExt.size()==levs.size()+1)
-               {
-                 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingMesh> m(mm->getGenMeshAtLevel(1));
-                 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES));
-                 f->setMesh(m);
-                 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());
-                 f1tsMultiLev->setFieldNoProfileSBT(f);
-               }
-             else
-               continue;
-           }
-       }
+        {
+          for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
+            {
+              std::vector<INTERP_KERNEL::NormalizedCellType> gts(mmu->getGeoTypesAtLevel(*it));
+              for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator gt=gts.begin();gt!=gts.end();gt++)
+                {
+                  ParaMEDMEM::MEDCouplingMesh *m(mmu->getDirectUndergroundSingleGeoTypeMesh(*gt));
+                  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS));
+                  f->setMesh(m);
+                  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected());
+                  arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
+                  arr->iota();
+                  f->setArray(arr);
+                  f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
+                  f1tsMultiLev->setFieldNoProfileSBT(f);
+                }
+            }
+          if(levs.empty())
+            {
+              std::vector<int> levsExt(mm->getNonEmptyLevelsExt());
+              if(levsExt.size()==levs.size()+1)
+                {
+                  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingMesh> m(mm->getGenMeshAtLevel(1));
+                  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES));
+                  f->setMesh(m);
+                  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(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
+                  f1tsMultiLev->setFieldNoProfileSBT(f);
+                }
+              else
+                continue;
+            }
+        }
       else
-       {
-         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingMesh> m(mm->getGenMeshAtLevel(0));
-         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS));
-         f->setMesh(m);
-         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected());
-         arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
-         arr->iota();
-         f->setArray(arr);
-         f->setName(mm->getName());
-         f1tsMultiLev->setFieldNoProfileSBT(f);
-       }
+        {
+          ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingMesh> m(mm->getGenMeshAtLevel(0));
+          ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS));
+          f->setMesh(m);
+          ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected());
+          arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
+          arr->iota();
+          f->setArray(arr);
+          f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
+          f1tsMultiLev->setFieldNoProfileSBT(f);
+        }
       //
       ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFieldMultiTS> fmtsMultiLev(ParaMEDMEM::MEDFileFieldMultiTS::New());
       fmtsMultiLev->pushBackTimeStep(f1tsMultiLev);
@@ -1369,6 +1474,20 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
     }
 }
 
+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());