Skip to content
Snippets Groups Projects
Commit 34220101 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

new addData() using a vector of vectors (instead of a map)

parent bc05e923
No related branches found
No related tags found
No related merge requests found
...@@ -152,7 +152,7 @@ PView::PView(const std::string &name, const std::string &type, ...@@ -152,7 +152,7 @@ PView::PView(const std::string &name, const std::string &type,
_options->targetError); _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) double time, int numComp)
{ {
PViewDataGModel *d = dynamic_cast<PViewDataGModel*>(_data); PViewDataGModel *d = dynamic_cast<PViewDataGModel*>(_data);
......
...@@ -58,7 +58,7 @@ class PView{ ...@@ -58,7 +58,7 @@ class PView{
std::map<int, std::vector<double> > &data, double time=0., std::map<int, std::vector<double> > &data, double time=0.,
int numComp = -1); int numComp = -1);
// add a new time step to a given mesh-based view // 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); double time=0.,int numComp = -1);
// default destructor // default destructor
......
...@@ -34,6 +34,9 @@ class stepData{ ...@@ -34,6 +34,9 @@ class stepData{
// optimal. This is the price to pay if we want 1) rapid access to // 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 // the data and 2) not to store any additional info in MVertex or
// MElement) // 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; std::vector<Real*> *_data;
// a vector containing the multiplying factor allowing to compute // a vector containing the multiplying factor allowing to compute
// the number of values stored in _data for each index (number of // the number of values stored in _data for each index (number of
...@@ -242,7 +245,12 @@ class PViewDataGModel : public PViewData { ...@@ -242,7 +245,12 @@ class PViewDataGModel : public PViewData {
// Add some data "on the fly" (data is stored in a map, indexed by // Add some data "on the fly" (data is stored in a map, indexed by
// node or element number depending on the type of dataset) // 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); int step, double time, int partition, int numComp);
// Allow to destroy the data // Allow to destroy the data
...@@ -252,8 +260,8 @@ class PViewDataGModel : public PViewData { ...@@ -252,8 +260,8 @@ class PViewDataGModel : public PViewData {
int fileIndex, FILE *fp, bool binary, bool swap, int step, int fileIndex, FILE *fp, bool binary, bool swap, int step,
double time, int partition, int numComp, int numNodes, double time, int partition, int numComp, int numNodes,
const std::string &interpolationScheme); const std::string &interpolationScheme);
virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, virtual bool writeMSH(const std::string &fileName, double version=2.2,
bool savemesh=true, bool multipleView=false, bool binary=false, bool savemesh=true, bool multipleView=false,
int partitionNum=0, bool saveInterpolationMatrices=true, int partitionNum=0, bool saveInterpolationMatrices=true,
bool forceNodeData=false, bool forceElementData=false); bool forceNodeData=false, bool forceElementData=false);
bool readMED(const std::string &fileName, int fileIndex); bool readMED(const std::string &fileName, int fileIndex);
......
...@@ -12,14 +12,15 @@ ...@@ -12,14 +12,15 @@
#include "StringUtils.h" #include "StringUtils.h"
#include "OS.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) int step, double time, int partition, int numComp)
{ {
if(data.empty()) return false; if(data.empty()) return false;
if (numComp < 0){ if (numComp < 0){
numComp = 9; 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++) it != data.end(); it++)
numComp = std::min(numComp, (int)it->second.size()); numComp = std::min(numComp, (int)it->second.size());
} }
...@@ -34,7 +35,7 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > ...@@ -34,7 +35,7 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> >
model->getNumMeshElements(); model->getNumMeshElements();
_steps[step]->resizeData(numEnt); _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++){ it != data.end(); it++){
int mult = it->second.size() / numComp; int mult = it->second.size() / numComp;
double *d = _steps[step]->getData(it->first, true, mult); double *d = _steps[step]->getData(it->first, true, mult);
...@@ -47,6 +48,42 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > ...@@ -47,6 +48,42 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> >
return true; 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() void PViewDataGModel::destroyData()
{ {
for(unsigned int i = 0; i < _steps.size(); i++) for(unsigned int i = 0; i < _steps.size(); i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment