diff --git a/Post/PView.cpp b/Post/PView.cpp index 51705e00fc668b265c8c4252ef3e978c3f38b15d..ac81e79b5a8258629bfb7bc6af5379464109a1fb 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 7113b495f00d778bdd110b148e341591ff234a17..3d5ab8cb0b9f7ad0f73de108ecf25353717ea171 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 e7af95139500bead32179a85452d754982864b39..78fb958d2b7e4c2f6558e1e64045a45f8932873f 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 fd6ee713dd85b2761fce0405546bd19bcb083835..c1b59a98e43ebb9f07744efc743ad66b17b93458 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++)