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

quick hack to implement a first version of combineTime for model-based datasets

FIXME: we need to store the number of things stored for each element in stepData 
to make this clean (and make high-order I/O easier) + add a copy constructor in stepData
parent c9f5c45d
No related branches found
No related tags found
No related merge requests found
......@@ -245,15 +245,32 @@ void PView::combine(bool time, int how, bool remove)
std::set<PView*> rm;
for(unsigned int i = 0; i < nds.size(); i++){
if(nds[i].data.size() > 1){
// there's potentially something to combine
PView *p = new PView();
PViewData *data = p->getData();
bool res = time ? data->combineTime(nds[i]): data->combineSpace(nds[i]);
if(nds[i].data.size() > 1){ // there's potentially something to combine
// sanity checks:
bool allListBased = true, allModelBased = true;
for(unsigned int j = 0; j < nds[i].data.size(); j++){
PViewDataList *d1 = dynamic_cast<PViewDataList*>(nds[i].data[j]);
if(!d1) allListBased = false;
PViewDataGModel *d2 = dynamic_cast<PViewDataGModel*>(nds[i].data[j]);
if(!d2) allModelBased = false;
}
PViewData *data = 0;
if(allListBased){
data = new PViewDataList();
}
else if(allModelBased){
PViewDataGModel *d2 = dynamic_cast<PViewDataGModel*>(nds[i].data[0]);
data = new PViewDataGModel(d2->getType());
}
else{
Msg::Error("Cannot combine hybrid list/model-based datasets");
continue;
}
PView *p = new PView(data);
bool res = time ? data->combineTime(nds[i]) : data->combineSpace(nds[i]);
if(res){
for(unsigned int j = 0; j < nds[i].indices.size(); j++)
rm.insert(list[nds[i].indices[j]]);
PViewOptions *opt = p->getOptions();
if(opt->adaptVisualizationGrid){
// the (empty) adaptive data created in PView() must be
......@@ -262,7 +279,6 @@ void PView::combine(bool time, int how, bool remove)
data->initAdaptiveData
(opt->timeStep, opt->maxRecursionLevel, opt->targetError);
}
}
else
delete p;
......
......@@ -495,6 +495,68 @@ void PViewDataGModel::smooth()
finalize();
}
bool PViewDataGModel::combineTime(nameData &nd)
{
// sanity checks
if(nd.data.size() < 2) return false;
std::vector<PViewDataGModel*> data(nd.data.size());
for(unsigned int i = 0; i < nd.data.size(); i++){
data[i] = dynamic_cast<PViewDataGModel*>(nd.data[i]);
if(!data[i]){
Msg::Error("Cannot combine hybrid data");
return false;
}
}
// copy interpolation matrices
for(std::map<int, std::vector<fullMatrix<double>*> >::iterator it =
data[0]->_interpolation.begin(); it != data[0]->_interpolation.end(); it++)
if(_interpolation[it->first].empty())
for(unsigned int i = 0; i < it->second.size(); i++)
_interpolation[it->first].push_back(new fullMatrix<double>(*it->second[i]));
for(unsigned int i = 0; i < data.size(); i++){
// FIXME: this is a horrible hack (we copy the data twice, and use
// a map!); we need to store the number of values per
// node/ele/... in stepData and provide a copy constructor, then
// just copy the stepData
for(unsigned int j = 0; j < data[i]->_steps.size(); j++){
if(data[i]->hasTimeStep(j)){
std::map<int, std::vector<double> > datamap;
if(getType() == NodeData){
stepData<double> *sd = data[i]->_steps[j];
for(unsigned int k = 0; k < sd->getNumData(); k++){
double *d = sd->getData(k);
if(d){
for(int l = 0; l < sd->getNumComponents(); l++){
datamap[k].push_back(d[l]);
}
}
}
}
else{
Msg::Error("Combine time not ready for non nodal model-based datasets");
}
addData(data[i]->getModel(j), datamap, i, data[i]->getTime(j), 0, -1);
}
}
}
std::string tmp;
if(nd.name == "__all__")
tmp = "all";
else if(nd.name == "__vis__")
tmp = "visible";
else
tmp = nd.name;
char name[256];
sprintf(name, "%s_Combine", tmp.c_str());
setName(name);
setFileName(std::string(name) + ".msh");
return finalize();
}
bool PViewDataGModel::skipEntity(int step, int ent)
{
if(step >= getNumTimeSteps()) return true;
......
......@@ -168,6 +168,7 @@ class PViewDataGModel : public PViewData {
int getType(int step, int ent, int ele);
void revertElement(int step, int ent, int ele);
void smooth();
bool combineTime(nameData &nd);
bool skipEntity(int step, int ent);
bool skipElement(int step, int ent, int ele, bool checkVisibility=false);
bool hasTimeStep(int step);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment