From 1f8e6370bc4016cdc10fbdfe55953bec42875732 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 2 May 2011 14:44:54 +0000
Subject: [PATCH] speed-up reading post-pro files in .msh with huge number of
 time steps (usually sparse) - for gauthier

---
 Post/PViewDataGModel.cpp   | 53 ++++++++++++++++++++------------------
 Post/PViewDataGModelIO.cpp | 12 ++++++---
 2 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp
index 26ef74a7b6..abbe772e38 100644
--- a/Post/PViewDataGModel.cpp
+++ b/Post/PViewDataGModel.cpp
@@ -66,31 +66,34 @@ bool PViewDataGModel::finalize(bool computeMinMax)
 
   // add interpolation data for known element types (this might be
   // overidden later)
-  for(int step = 0; step < getNumTimeSteps(); step++){
-    GModel *m = _steps[step]->getModel();
-    for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
-      if((*it)->lines.size())
-        _addInterpolationMatricesForElement((*it)->lines[0]);
-    }
-    for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
-      if((*it)->triangles.size())
-        _addInterpolationMatricesForElement((*it)->triangles[0]);
-      if((*it)->quadrangles.size())
-        _addInterpolationMatricesForElement((*it)->quadrangles[0]);
-      if((*it)->polygons.size())
-        _addInterpolationMatricesForElement((*it)->polygons[0]);
-    }
-    for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
-      if((*it)->tetrahedra.size())
-        _addInterpolationMatricesForElement((*it)->tetrahedra[0]);
-      if((*it)->hexahedra.size())
-        _addInterpolationMatricesForElement((*it)->hexahedra[0]);
-      if((*it)->prisms.size())
-        _addInterpolationMatricesForElement((*it)->prisms[0]);
-      if((*it)->pyramids.size())
-        _addInterpolationMatricesForElement((*it)->pyramids[0]);
-      if((*it)->polyhedra.size())
-        _addInterpolationMatricesForElement((*it)->polyhedra[0]);
+  if(!haveInterpolationMatrices()){
+    for(int step = 0; step < getNumTimeSteps(); step++){
+      if(!_steps[step]->getNumData()) continue;
+      GModel *m = _steps[step]->getModel();
+      for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
+        if((*it)->lines.size())
+          _addInterpolationMatricesForElement((*it)->lines[0]);
+      }
+      for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
+        if((*it)->triangles.size())
+          _addInterpolationMatricesForElement((*it)->triangles[0]);
+        if((*it)->quadrangles.size())
+          _addInterpolationMatricesForElement((*it)->quadrangles[0]);
+        if((*it)->polygons.size())
+          _addInterpolationMatricesForElement((*it)->polygons[0]);
+      }
+      for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
+        if((*it)->tetrahedra.size())
+          _addInterpolationMatricesForElement((*it)->tetrahedra[0]);
+        if((*it)->hexahedra.size())
+          _addInterpolationMatricesForElement((*it)->hexahedra[0]);
+        if((*it)->prisms.size())
+          _addInterpolationMatricesForElement((*it)->prisms[0]);
+        if((*it)->pyramids.size())
+          _addInterpolationMatricesForElement((*it)->pyramids[0]);
+        if((*it)->polyhedra.size())
+          _addInterpolationMatricesForElement((*it)->polyhedra[0]);
+      }
     }
   }
 
diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp
index 4d572d70b4..b471970040 100644
--- a/Post/PViewDataGModelIO.cpp
+++ b/Post/PViewDataGModelIO.cpp
@@ -52,18 +52,24 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp,
   Msg::Info("Reading step %d (time %g) partition %d: %d records",
             step, time, partition, numEnt);
 
-  while(step >= (int)_steps.size())
-    _steps.push_back(new stepData<double>(GModel::current(), numComp));
-
+  while(step >= (int)_steps.size()){
+    if(_steps.empty() || _steps.back()->getNumData())
+      _steps.push_back(new stepData<double>(GModel::current(), numComp));
+    else // faster since we avoid computing model bounds
+      _steps.push_back(new stepData<double>(*_steps.back()));
+  }
+  
   _steps[step]->setFileName(fileName);
   _steps[step]->setFileIndex(fileIndex);
   _steps[step]->setTime(time);
 
+  /*
   // if we already have maxSteps for this view, return
   int numSteps = 0, maxSteps = 1000000000;
   for(unsigned int i = 0; i < _steps.size(); i++)
     numSteps += _steps[i]->getNumData() ? 1 : 0;
   if(numSteps > maxSteps) return true;
+  */
 
   _steps[step]->resizeData(numEnt);
 
-- 
GitLab