Salome HOME
Merge branch 'master' into V7_5_BR
[modules/paravis.git] / src / Plugins / MEDReader / IO / MEDFileFieldRepresentationTree.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 26a9c6c..6cf1d80
 #include "MEDFileData.hxx"
 #include "SauvReader.hxx"
 
+#ifdef MEDREADER_USE_MPI
+  #include "ParaMEDFileMesh.hxx"
+#endif
+
 #include "vtkXMLUnstructuredGridWriter.h"//
 
 #include "vtkUnstructuredGrid.h"
@@ -1087,12 +1091,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
     {
@@ -1134,7 +1159,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());
@@ -1353,6 +1395,8 @@ void MEDFileFieldRepresentationTree::printMySelf(std::ostream& os) const
 
 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));
@@ -1373,7 +1417,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
                  arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
                  arr->iota();
                  f->setArray(arr);
-                 f->setName(mm->getName());
+                 f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
                  f1tsMultiLev->setFieldNoProfileSBT(f);
                }
            }
@@ -1388,7 +1432,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
                  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());
+                 f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
                  f1tsMultiLev->setFieldNoProfileSBT(f);
                }
              else
@@ -1404,7 +1448,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
          arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
          arr->iota();
          f->setArray(arr);
-         f->setName(mm->getName());
+         f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
          f1tsMultiLev->setFieldNoProfileSBT(f);
        }
       //
@@ -1414,6 +1458,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());