Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/paravis
[modules/paravis.git] / src / Plugins / MEDReader / IO / MEDFileFieldRepresentationTree.cxx
index 089d54ab28d0a71d96b3e44473dcc21f05a7bbe0..26a9c6cd08d1faa0c63bdaba0f03a269303d7417 100644 (file)
@@ -3,7 +3,7 @@
 // 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
@@ -136,7 +136,13 @@ vtkIdTypeArray *ELGACmp::createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *glob
       for(int i=0;i<nbGaussPt;i++)
         {
           const double *pt0(calculator.getFunctionValues(i));
-          std::copy(pt0,pt0+nbPtsPerCell,shape+nbPtsPerCell*i);
+          if(ct!=INTERP_KERNEL::NORM_HEXA27)
+            std::copy(pt0,pt0+nbPtsPerCell,shape+nbPtsPerCell*i);
+          else
+            {
+              for(int j=0;j<27;j++)
+                shape[nbPtsPerCell*i+j]=pt0[MEDMeshMultiLev::HEXA27_PERM_ARRAY[j]];
+            }
         }
       unsigned char vtkType(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[ct]);
       m[vtkType]=nbGaussPt;
@@ -228,12 +234,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())))
     {
@@ -242,6 +251,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;
@@ -463,15 +478,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"));
@@ -878,6 +899,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++)
@@ -932,7 +975,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);
             } 
         }
     }
@@ -1000,6 +1043,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));
@@ -1014,7 +1063,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
@@ -1069,6 +1119,7 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
     {
       AppendFieldFromMeshes(_ms,_fields);
     }
+  _fields->removeFieldsWithoutAnyTimeStep();
   std::vector<std::string> meshNames(_ms->getMeshesNames());
   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFields> > fields_per_mesh(meshNames.size());
   for(std::size_t i=0;i<meshNames.size();i++)
@@ -1149,6 +1200,7 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
     }
   this->removeEmptyLeaves();
   this->assignIds();
+  this->computeFullNameInLeaves();
 }
 
 void MEDFileFieldRepresentationTree::removeEmptyLeaves()
@@ -1245,7 +1297,7 @@ vtkDataSet *MEDFileFieldRepresentationTree::buildVTKInstance(bool isStdOrMode, d
   if(!isStdOrMode)
     tr=new MEDStdTimeReq((int)zeTimeId);
   else
-    tr=new MEDModeTimeReq(tk.getTheVectOfBool());
+    tr=new MEDModeTimeReq(tk.getTheVectOfBool(),tk.getPostProcessedTime());
   vtkDataSet *ret(leaf.buildVTKInstanceNoTimeInterpolation(tr,_fields,_ms));
   delete tr;
   return ret;
@@ -1304,44 +1356,57 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
   for(int i=0;i<ms->getNumberOfMeshes();i++)
     {
       MEDFileMesh *mm(ms->getMeshAtPos(i));
-      MEDFileUMesh *mmu(dynamic_cast<MEDFileUMesh *>(mm));
-      if(!mmu)
-        continue;
       std::vector<int> levs(mm->getNonEmptyLevels());
       ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileField1TS> f1tsMultiLev(ParaMEDMEM::MEDFileField1TS::New());
-      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;
-        }
+      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;
+           }
+       }
+      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::MEDFileFieldMultiTS> fmtsMultiLev(ParaMEDMEM::MEDFileFieldMultiTS::New());
       fmtsMultiLev->pushBackTimeStep(f1tsMultiLev);
@@ -1356,6 +1421,74 @@ ParaMEDMEM::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(
   return ret.retn();
 }
 
+std::vector<std::string> MEDFileFieldRepresentationTree::SplitFieldNameIntoParts(const std::string& fullFieldName, char sep)
+{
+  std::vector<std::string> ret;
+  std::size_t pos(0);
+  while(pos!=std::string::npos)
+    {
+      std::size_t curPos(fullFieldName.find_first_of(sep,pos));
+      std::string elt(fullFieldName.substr(pos,curPos!=std::string::npos?curPos-pos:std::string::npos));
+      ret.push_back(elt);
+      pos=fullFieldName.find_first_not_of(sep,curPos);
+    }
+  return ret;
+}
+
+/*!
+ * Here the non regression tests.
+ * const char inp0[]="";
+ * const char exp0[]="";
+ * const char inp1[]="field";
+ * const char exp1[]="field";
+ * const char inp2[]="_________";
+ * const char exp2[]="_________";
+ * const char inp3[]="field_p";
+ * const char exp3[]="field_p";
+ * const char inp4[]="field__p";
+ * const char exp4[]="field_p";
+ * const char inp5[]="field_p__";
+ * const char exp5[]="field_p";
+ * const char inp6[]="field_p_";
+ * const char exp6[]="field_p";
+ * const char inp7[]="field_____EDFGEG//sdkjf_____PP_______________";
+ * const char exp7[]="field_EDFGEG//sdkjf_PP";
+ * const char inp8[]="field_____EDFGEG//sdkjf_____PP";
+ * const char exp8[]="field_EDFGEG//sdkjf_PP";
+ * const char inp9[]="_field_____EDFGEG//sdkjf_____PP_______________";
+ * const char exp9[]="field_EDFGEG//sdkjf_PP";
+ * const char inp10[]="___field_____EDFGEG//sdkjf_____PP_______________";
+ * const char exp10[]="field_EDFGEG//sdkjf_PP";
+*/
+std::string MEDFileFieldRepresentationTree::PostProcessFieldName(const std::string& fullFieldName)
+{
+  static const char SEP('_');
+  std::vector<std::string> v(SplitFieldNameIntoParts(fullFieldName,SEP));
+  if(v.empty())
+    return fullFieldName;//should never happen
+  if(v.size()==1)
+    {
+      if(v[0].empty())
+        return fullFieldName;
+      else
+        return v[0];
+    }
+  std::string ret(v[0]);
+  for(std::size_t i=1;i<v.size();i++)
+    {
+      if(!v[i].empty())
+        {
+          if(!ret.empty())
+            { ret+=SEP; ret+=v[i]; }
+          else
+            ret=v[i];
+        }
+    }
+  if(ret.empty())
+    return fullFieldName;
+  return ret;
+}
+
 ///////////
 
 TimeKeeper::TimeKeeper(int policy):_policy(policy)