Salome HOME
PV 5.4 : Porting to OpenGL2
[modules/paravis.git] / src / Plugins / MEDReader / IO / MEDFileFieldRepresentationTree.cxx
index d5f991024dbbc236977e25b7ebc6709cea4bb606..d87827ac17478b2e3e508c24d7c5623c31aed991 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2016  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
@@ -42,6 +42,7 @@
 #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
 #include "vtkInformationIntegerKey.h"
 #include "vtkInformation.h"
+#include "vtkDataArrayTemplate.h"
 #include "vtkIdTypeArray.h"
 #include "vtkDoubleArray.h"
 #include "vtkIntArray.h"
@@ -76,7 +77,7 @@ const char MEDFileFieldRepresentationTree::ROOT_OF_FAM_IDS_IN_TREE[]="zeFamIds";
 
 const char MEDFileFieldRepresentationTree::COMPO_STR_TO_LOCATE_MESH_DA[]="-@?|*_";
 
-vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const
+vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew, ExportedTinyInfo *internalInfo) const
 {
   vtkIdTypeArray *try0(isExisting(locsReallyUsed,vtkd));
   if(try0)
@@ -87,7 +88,7 @@ vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *
   else
     {
       isNew=true;
-      return createNew(globs,locsReallyUsed,vtkd,ds);
+      return createNew(globs,locsReallyUsed,vtkd,ds,internalInfo);
     }
 }
 
@@ -107,7 +108,7 @@ vtkIdTypeArray *ELGACmp::isExisting(const std::vector<std::string>& locsReallyUs
   return ret;
 }
 
-vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const
+vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const
 {
   const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
   std::vector< std::vector<std::string> > locNames(_loc_names);
@@ -127,11 +128,14 @@ vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *glo
       vtkQuadratureSchemeDefinition *def(vtkQuadratureSchemeDefinition::New());
       const MEDFileFieldLoc& loc(globs->getLocalization((*it).c_str()));
       INTERP_KERNEL::NormalizedCellType ct(loc.getGeoType());
+      unsigned char vtkType(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[ct]);
       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(ct));
       int nbGaussPt(loc.getNbOfGaussPtPerCell()),nbPtsPerCell((int)cm.getNumberOfNodes()),dimLoc(loc.getDimension());
       // WARNING : these 2 lines are a workaround, due to users that write a ref element with dimension not equal to dimension of the geometric element.
       std::vector<double> gsCoods2(INTERP_KERNEL::GaussInfo::NormalizeCoordinatesIfNecessary(ct,dimLoc,loc.getGaussCoords()));
       std::vector<double> refCoods2(INTERP_KERNEL::GaussInfo::NormalizeCoordinatesIfNecessary(ct,dimLoc,loc.getRefCoords()));
+      if(internalInfo)
+        internalInfo->pushGaussAdditionnalInfo(vtkType,dimLoc,refCoods2,gsCoods2);
       double *shape(new double[nbPtsPerCell*nbGaussPt]);
       INTERP_KERNEL::GaussInfo calculator(ct,gsCoods2,nbGaussPt,refCoods2,nbPtsPerCell);
       calculator.initLocalInfo();
@@ -147,7 +151,6 @@ vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *glo
                 shape[nbPtsPerCell*i+j]=pt0[MEDMeshMultiLev::HEXA27_PERM_ARRAY[j]];
             }
         }
-      unsigned char vtkType(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[ct]);
       m[vtkType]=nbGaussPt;
       def->Initialize(vtkType,nbPtsPerCell,nbGaussPt,shape,const_cast<double *>(&wgths[0]));
       delete [] shape;
@@ -316,7 +319,7 @@ bool MEDFileFieldRepresentationLeavesArrays::setStatus(bool status) const
   return ret;
 }
 
-void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshStruct *mst, vtkDataSet *ds) const
+void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshStruct *mst, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const
 {
   const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
   tr->setNumberOfTS((operator->())->getNumberOfTS());
@@ -383,7 +386,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr,
           if(discs[0]==ON_GAUSS_PT)
             {
               bool tmp;
-              _elga_cmp.findOrCreate(globs,f1ts->getLocsReallyUsed(),vtkd,ds,tmp);
+              _elga_cmp.findOrCreate(globs,f1ts->getLocsReallyUsed(),vtkd,ds,tmp,internalInfo);
             }
           if(discs[0]==ON_GAUSS_NE)
             {
@@ -420,7 +423,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr,
                   vtkQuadratureSchemeDefinition *def(vtkQuadratureSchemeDefinition::New());
                   double *shape(new double[nbGaussPt*nbGaussPt]);
                   std::size_t dummy;
-                  const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(ct,dummy));
+                  const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));//GetLocsFromGeometricType
                   const double *refCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));
                   const double *weights(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(ct,dummy));
                   std::vector<double> gsCoords2(gsCoords,gsCoords+nbGaussPt*dim),refCoords2(refCoords,refCoords+nbGaussPt*dim);
@@ -647,7 +650,7 @@ std::string MEDFileFieldRepresentationLeaves::getHumanReadableOverviewOfTS() con
   return oss.str();
 }
 
-void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshes *meshes, vtkDataSet *ds) const
+void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshes *meshes, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const
 {
   if(_arrays.size()<1)
     throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeaves::appendFields : internal error !");
@@ -655,7 +658,7 @@ void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const
   for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
     if((*it).getStatus())
       {
-        (*it).appendFields(tr,globs,mml,mst,ds);
+        (*it).appendFields(tr,globs,mml,mst,ds,internalInfo);
         (*it).appendELGAIfAny(ds);
       }
 }
@@ -786,7 +789,7 @@ vtkStructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInter
   return ret;
 }
  
-vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDFileMeshes *meshes) const
+vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDFileMeshes *meshes, ExportedTinyInfo *internalInfo) const
 {
   vtkDataSet *ret(0);
   //_fsp->isDataSetSupportEqualToThePreviousOne(i,globs);
@@ -822,7 +825,7 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio
       ret->ShallowCopy(_cached_ds);
     }
   //
-  appendFields(tr,globs,mml,meshes,ret);
+  appendFields(tr,globs,mml,meshes,ret,internalInfo);
   // The arrays links to mesh
   DataArrayInt *famCells(0),*numCells(0);
   bool noCpyFamCells(false),noCpyNumCells(false);
@@ -857,7 +860,7 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio
       vtkIntArray *vtkTab(vtkIntArray::New());
       vtkTab->SetNumberOfComponents(1);
       vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME);
-      AssignDataPointerToVTK<int>(vtkTab,famNodes,noCpyNumNodes);
+      AssignDataPointerToVTK<int>(vtkTab,famNodes,noCpyFamNodes);
       ret->GetPointData()->AddArray(vtkTab);
       vtkTab->Delete();
       famNodes->decrRef();
@@ -994,6 +997,13 @@ void MEDFileFieldRepresentationTree::feedSIL(vtkMutableDirectedGraph* sil, vtkId
     }
 }
 
+std::string MEDFileFieldRepresentationTree::getActiveMeshName() const
+{
+  int dummy0(0),dummy1(0),dummy2(0);
+  const MEDFileFieldRepresentationLeaves& leaf(getTheSingleActivated(dummy0,dummy1,dummy2));
+  return leaf.getMeshName();
+}
+
 std::string MEDFileFieldRepresentationTree::feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const
 {
   int dummy0(0),dummy1(0),dummy2(0);
@@ -1100,52 +1110,15 @@ int MEDFileFieldRepresentationTree::getMaxNumberOfTimeSteps() const
 /*!
  * 
  */
-void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts)
+void MEDFileFieldRepresentationTree::loadInMemory(MEDCoupling::MEDFileFields *fields, MEDCoupling::MEDFileMeshes *meshes)
 {
-  if(isMEDOrSauv)
-    {
-      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++)
-            {
-              MEDCoupling::MEDFileMesh *tmp(_ms->getMeshAtPos(i));
-              MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast<MEDCoupling::MEDFileUMesh *>(tmp));
-              if(tmp2)
-                MCAuto<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
-    {
-      MCAuto<MEDCoupling::SauvReader> sr(MEDCoupling::SauvReader::New(fileName));
-      MCAuto<MEDCoupling::MEDFileData> mfd(sr->loadInMEDFileDS());
-      _ms=mfd->getMeshes(); _ms->incrRef();
-      int nbMeshes(_ms->getNumberOfMeshes());
-      for(int i=0;i<nbMeshes;i++)
-        {
-          MEDCoupling::MEDFileMesh *tmp(_ms->getMeshAtPos(i));
-          MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast<MEDCoupling::MEDFileUMesh *>(tmp));
-          if(tmp2)
-            tmp2->forceComputationOfParts();
-        }
-      _fields=mfd->getFields();
-      if((MEDCoupling::MEDFileFields *)_fields)
-        _fields->incrRef();
-    }
-  if(!((MEDCoupling::MEDFileFields *)_fields))
+  _fields=fields; _ms=meshes;
+  if(_fields.isNotNull())
+    _fields->incrRef();
+  if(_ms.isNotNull())
+    _ms->incrRef();
+  //
+  if(_fields.isNull())
     {
       _fields=BuildFieldFromMeshes(_ms);
     }
@@ -1255,6 +1228,71 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
   this->computeFullNameInLeaves();
 }
 
+void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts)
+{
+  MCAuto<MEDFileMeshes> ms;
+  MCAuto<MEDFileFields> fields;
+  if(isMEDOrSauv)
+    {
+      if((iPart==-1 && nbOfParts==-1) || (iPart==0 && nbOfParts==1))
+        {
+          MCAuto<MEDFileMeshSupports> msups(MEDFileMeshSupports::New(fileName));
+          MCAuto<MEDFileStructureElements> mse(MEDFileStructureElements::New(fileName,msups));
+          ms=MEDFileMeshes::New(fileName);
+          fields=MEDFileFields::NewWithDynGT(fileName,mse,false);//false is important to not read the values
+          if(ms->presenceOfStructureElements())
+            {// pre traitement
+              fields->loadArrays();
+              fields->blowUpSE(ms,mse);
+            }
+          int nbMeshes(ms->getNumberOfMeshes());
+          for(int i=0;i<nbMeshes;i++)
+            {
+              MEDCoupling::MEDFileMesh *tmp(ms->getMeshAtPos(i));
+              MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast<MEDCoupling::MEDFileUMesh *>(tmp));
+              if(tmp2)
+                tmp2->forceComputationOfParts();
+            }
+        }
+      else
+        {
+#ifdef MEDREADER_USE_MPI
+          ms=ParaMEDFileMeshes::New(iPart,nbOfParts,fileName);
+          int nbMeshes(ms->getNumberOfMeshes());
+          for(int i=0;i<nbMeshes;i++)
+            {
+              MEDCoupling::MEDFileMesh *tmp(ms->getMeshAtPos(i));
+              MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast<MEDCoupling::MEDFileUMesh *>(tmp));
+              if(tmp2)
+                MCAuto<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
+    {
+      MCAuto<MEDCoupling::SauvReader> sr(MEDCoupling::SauvReader::New(fileName));
+      MCAuto<MEDCoupling::MEDFileData> mfd(sr->loadInMEDFileDS());
+      ms=mfd->getMeshes(); ms->incrRef();
+      int nbMeshes(ms->getNumberOfMeshes());
+      for(int i=0;i<nbMeshes;i++)
+        {
+          MEDCoupling::MEDFileMesh *tmp(ms->getMeshAtPos(i));
+          MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast<MEDCoupling::MEDFileUMesh *>(tmp));
+          if(tmp2)
+            tmp2->forceComputationOfParts();
+        }
+      fields=mfd->getFields();
+      if(fields.isNotNull())
+        fields->incrRef();
+    }
+  loadInMemory(fields,ms);
+}
+
 void MEDFileFieldRepresentationTree::removeEmptyLeaves()
 {
   std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > newSD;
@@ -1294,7 +1332,7 @@ std::vector<double> MEDFileFieldRepresentationTree::getTimeSteps(int& lev0, cons
   return leaf.getTimeSteps(tk);
 }
 
-vtkDataSet *MEDFileFieldRepresentationTree::buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk) const
+vtkDataSet *MEDFileFieldRepresentationTree::buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk, ExportedTinyInfo *internalInfo) const
 {
   int lev0,lev1,lev2;
   const MEDFileFieldRepresentationLeaves& leaf(getTheSingleActivated(lev0,lev1,lev2));
@@ -1350,7 +1388,7 @@ vtkDataSet *MEDFileFieldRepresentationTree::buildVTKInstance(bool isStdOrMode, d
     tr=new MEDStdTimeReq((int)zeTimeId);
   else
     tr=new MEDModeTimeReq(tk.getTheVectOfBool(),tk.getPostProcessedTime());
-  vtkDataSet *ret(leaf.buildVTKInstanceNoTimeInterpolation(tr,_fields,_ms));
+  vtkDataSet *ret(leaf.buildVTKInstanceNoTimeInterpolation(tr,_fields,_ms,internalInfo));
   delete tr;
   return ret;
 }