From 02858ad68ee91677f2cfab617ca364bc15b03ad6 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 23 Jul 2012 20:51:14 +0000 Subject: [PATCH] reduce memory overhead of empty steps in model-based views (best solution would be not to allocate empty steps at all -- todo...) --- Post/PViewDataGModel.h | 11 ++++++----- Post/PViewDataGModelIO.cpp | 28 ++++++++++++++-------------- Post/PViewIO.cpp | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 17fef229f8..d436e746d1 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -51,8 +51,6 @@ class stepData{ : _model(model), _fileName(fileName), _fileIndex(fileIndex), _time(time), _min(min), _max(max), _numComp(numComp), _data(0) { - _model->getEntities(_entities); - _bbox = _model->bounds(); } stepData(stepData<real> &other) : _data(0) { @@ -82,6 +80,8 @@ class stepData{ _partitions = other._partitions; } ~stepData(){ destroyData(); } + void fillEntities(){ _model->getEntities(_entities); } + void computeBoundingBox(){ _bbox = _model->bounds(); } GModel *getModel(){ return _model; } SBoundingBox3d getBoundingBox(){ return _bbox; } int getNumEntities(){ return _entities.size(); } @@ -235,9 +235,10 @@ class PViewDataGModel : public PViewData { int step, double time, int partition, int numComp); // I/O routines - bool readMSH(const std::string &fileName, int fileIndex, FILE *fp, bool binary, - bool swap, int step, double time, int partition, - int numComp, int numNodes, const std::string &interpolationScheme); + bool readMSH(const std::string &viewName, const std::string &fileName, + int fileIndex, FILE *fp, bool binary, bool swap, int step, + double time, int partition, int numComp, int numNodes, + const std::string &interpolationScheme); bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true); bool readMED(const std::string &fileName, int fileIndex); bool writeMED(const std::string &fileName); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index ee96335450..62260558b8 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -25,7 +25,8 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > while(step >= (int)_steps.size()) _steps.push_back(new stepData<double>(model, numComp)); - + _steps[step]->fillEntities(); + _steps[step]->computeBoundingBox(); _steps[step]->setTime(time); int numEnt = (_type == NodeData) ? model->getNumMeshVertices() : @@ -45,21 +46,18 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > return true; } -bool PViewDataGModel::readMSH(const std::string &fileName, int fileIndex, FILE *fp, - bool binary, bool swap, int step, double time, - int partition, int numComp, int numEnt, - const std::string &interpolationScheme) +bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fileName, + int fileIndex, FILE *fp, bool binary, bool swap, + int step, double time, int partition, int numComp, + int numEnt, const std::string &interpolationScheme) { - Msg::Info("Reading step %d (time %g) partition %d: %d records", - step, time, partition, numEnt); - - 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())); - } + Msg::Info("Reading view `%s' step %d (time %g) partition %d: %d records", + viewName.c_str(), step, time, partition, numEnt); + while(step >= (int)_steps.size()) + _steps.push_back(new stepData<double>(GModel::current(), numComp)); + _steps[step]->fillEntities(); + _steps[step]->computeBoundingBox(); _steps[step]->setFileName(fileName); _steps[step]->setFileIndex(fileIndex); _steps[step]->setTime(time); @@ -423,6 +421,8 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) } while(step >= (int)_steps.size()) _steps.push_back(new stepData<double>(m, numCompMsh)); + _steps[step]->fillEntities(); + _steps[step]->computeBoundingBox(); _steps[step]->setFileName(fileName); _steps[step]->setFileIndex(fileIndex); _steps[step]->setTime(dt); diff --git a/Post/PViewIO.cpp b/Post/PViewIO.cpp index 166aa545c7..371eb71c15 100644 --- a/Post/PViewIO.cpp +++ b/Post/PViewIO.cpp @@ -210,7 +210,7 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) if(p) d = dynamic_cast<PViewDataGModel*>(p->getData()); bool create = d ? false : true; if(create) d = new PViewDataGModel(type); - if(!d->readMSH(fileName, fileIndex, fp, binary, swap, timeStep, + if(!d->readMSH(viewName, fileName, fileIndex, fp, binary, swap, timeStep, time, partition, numComp, numEnt, interpolationScheme)){ Msg::Error("Could not read data in msh file"); if(create) delete d; -- GitLab