From 3422010173f7e5e205b2545fd7ffec5afc6568c3 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 22 Nov 2017 14:09:48 +0100 Subject: [PATCH] new addData() using a vector of vectors (instead of a map) --- Post/PView.cpp | 2 +- Post/PView.h | 2 +- Post/PViewDataGModel.h | 14 ++++++++++--- Post/PViewDataGModelIO.cpp | 43 +++++++++++++++++++++++++++++++++++--- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Post/PView.cpp b/Post/PView.cpp index 51705e00fc..ac81e79b5a 100644 --- a/Post/PView.cpp +++ b/Post/PView.cpp @@ -152,7 +152,7 @@ PView::PView(const std::string &name, const std::string &type, _options->targetError); } -void PView::addStep(GModel *model, std::map<int, std::vector<double> > &data, +void PView::addStep(GModel *model, const std::map<int, std::vector<double> > &data, double time, int numComp) { PViewDataGModel *d = dynamic_cast<PViewDataGModel*>(_data); diff --git a/Post/PView.h b/Post/PView.h index 7113b495f0..3d5ab8cb0b 100644 --- a/Post/PView.h +++ b/Post/PView.h @@ -58,7 +58,7 @@ class PView{ std::map<int, std::vector<double> > &data, double time=0., int numComp = -1); // add a new time step to a given mesh-based view - void addStep(GModel *model, std::map<int, std::vector<double> > &data, + void addStep(GModel *model, const std::map<int, std::vector<double> > &data, double time=0.,int numComp = -1); // default destructor diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index e7af951395..78fb958d2b 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -34,6 +34,9 @@ class stepData{ // optimal. This is the price to pay if we want 1) rapid access to // the data and 2) not to store any additional info in MVertex or // MElement) + // + // FIXME: we should change this design and store a vector<int> of tags, and do + // indirect addressing, even if it's a bit slower... std::vector<Real*> *_data; // a vector containing the multiplying factor allowing to compute // the number of values stored in _data for each index (number of @@ -242,7 +245,12 @@ class PViewDataGModel : public PViewData { // Add some data "on the fly" (data is stored in a map, indexed by // node or element number depending on the type of dataset) - bool addData(GModel *model, std::map<int, std::vector<double> > &data, + bool addData(GModel *model, const std::map<int, std::vector<double> > &data, + int step, double time, int partition, int numComp); + + // Add some data "on the fly", without a map + bool addData(GModel *model, const std::vector<int> &tags, + const std::vector<std::vector<double> > &data, int step, double time, int partition, int numComp); // Allow to destroy the data @@ -252,8 +260,8 @@ class PViewDataGModel : public PViewData { int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, int numComp, int numNodes, const std::string &interpolationScheme); - virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, - bool savemesh=true, bool multipleView=false, + virtual bool writeMSH(const std::string &fileName, double version=2.2, + bool binary=false, bool savemesh=true, bool multipleView=false, int partitionNum=0, bool saveInterpolationMatrices=true, bool forceNodeData=false, bool forceElementData=false); bool readMED(const std::string &fileName, int fileIndex); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index fd6ee713dd..c1b59a98e4 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -12,14 +12,15 @@ #include "StringUtils.h" #include "OS.h" -bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > &data, +bool PViewDataGModel::addData(GModel *model, + const std::map<int, std::vector<double> > &data, int step, double time, int partition, int numComp) { if(data.empty()) return false; if (numComp < 0){ numComp = 9; - for(std::map<int, std::vector<double> >::iterator it = data.begin(); + for(std::map<int, std::vector<double> >::const_iterator it = data.begin(); it != data.end(); it++) numComp = std::min(numComp, (int)it->second.size()); } @@ -34,7 +35,7 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > model->getNumMeshElements(); _steps[step]->resizeData(numEnt); - for(std::map<int, std::vector<double> >::iterator it = data.begin(); + for(std::map<int, std::vector<double> >::const_iterator it = data.begin(); it != data.end(); it++){ int mult = it->second.size() / numComp; double *d = _steps[step]->getData(it->first, true, mult); @@ -47,6 +48,42 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > return true; } +bool PViewDataGModel::addData(GModel *model, + const std::vector<int> &tags, + const std::vector<std::vector<double> > &data, + int step, double time, int partition, int numComp) +{ + printf("data size %d tag size %d\n", data.size() , tags.size()); + if(data.empty() || tags.empty() || data.size() != tags.size()) return false; + + if (numComp < 0){ + numComp = 9; + for(unsigned int i = 0; i < data.size(); i++) + numComp = std::min(numComp, (int)data[i].size()); + } + + 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() : + model->getNumMeshElements(); + _steps[step]->resizeData(numEnt); + + for(unsigned int i = 0; i < data.size(); i++){ + int mult = data[i].size() / numComp; + double *d = _steps[step]->getData(tags[i], true, mult); + for(int j = 0; j < numComp * mult; j++) + d[j] = data[i][j]; + } + if(partition >= 0) + _steps[step]->getPartitions().insert(partition); + finalize(); + return true; +} + void PViewDataGModel::destroyData() { for(unsigned int i = 0; i < _steps.size(); i++) -- GitLab