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

first pass at a fromVector/toVector serialization of PViews

parent d040e0c1
No related branches found
No related tags found
No related merge requests found
...@@ -255,6 +255,8 @@ class PViewData { ...@@ -255,6 +255,8 @@ class PViewData {
bool append=false); bool append=false);
virtual bool writeMSH(std::string fileName, bool binary=false, bool savemesh=true); virtual bool writeMSH(std::string fileName, bool binary=false, bool savemesh=true);
virtual bool writeMED(std::string fileName); virtual bool writeMED(std::string fileName);
virtual bool toVector(std::vector<std::vector<double> > &vec);
virtual bool fromVector(const std::vector<std::vector<double> > &vec);
}; };
class nameData{ class nameData{
......
...@@ -185,3 +185,58 @@ bool PViewData::writeMED(std::string fileName) ...@@ -185,3 +185,58 @@ bool PViewData::writeMED(std::string fileName)
Msg::Error("MED export onnly available for mesh-based post-processing views"); Msg::Error("MED export onnly available for mesh-based post-processing views");
return false; return false;
} }
bool PViewData::toVector(std::vector<std::vector<double> > &vec)
{
vec.resize(getNumTimeSteps());
for(int step = 0; step < getNumTimeSteps(); step++){
vec[step].clear();
for(int ent = 0; ent < getNumEntities(step); ent++){
for(int ele = 0; ele < getNumElements(step, ent); ele++){
if(skipElement(step, ent, ele)) continue;
for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){
for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){
double val;
getValue(step, ent, ele, nod, comp, val);
vec[step].push_back(val);
}
}
}
}
}
return true;
}
bool PViewData::fromVector(const std::vector<std::vector<double> > &vec)
{
if(vec.size() != getNumTimeSteps()){
Msg::Error("Incompatible number of steps in vector (%d) and view (%d)",
(int)vec.size(), getNumTimeSteps());
return false;
}
for(int step = 0; step < getNumTimeSteps(); step++){
int i = 0;
for(int ent = 0; ent < getNumEntities(step); ent++){
for(int ele = 0; ele < getNumElements(step, ent); ele++){
if(skipElement(step, ent, ele)) continue;
for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){
double x, y, z;
int tag = getNode(step, ent, ele, nod, x, y, z);
if(tag) continue; // node has already been modified
tagNode(step, ent, ele, nod, 1);
for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){
if(i < vec[step].size()){
setValue(step, ent, ele, nod, comp, vec[step][i++]);
}
else{
Msg::Error("Bad index (%d) in vector (%d)", i, (int)vec[step].size());
return false;
}
}
}
}
}
}
return true;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment