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

basic IO for new node based data; should be enough for tests

parent 5e3944ee
No related branches found
No related tags found
No related merge requests found
// $Id: PViewDataGModel.cpp,v 1.24 2008-03-10 16:01:16 geuzaine Exp $
// $Id: PViewDataGModel.cpp,v 1.25 2008-03-10 19:59:01 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -66,7 +66,7 @@ int PViewDataGModel::getNumTimeSteps()
double PViewDataGModel::getTime(int step)
{
if(step < _nodeData.size() && _nodeData[step])
if(step < (int)_nodeData.size() && _nodeData[step])
return _nodeData[step]->time;
return 0.;
}
......@@ -74,14 +74,14 @@ double PViewDataGModel::getTime(int step)
double PViewDataGModel::getMin(int step)
{
if(step < 0) return _min;
if(step < _nodeData.size() && _nodeData[step]) return _nodeData[step]->min;
if(step < (int)_nodeData.size() && _nodeData[step]) return _nodeData[step]->min;
return 0.;
}
double PViewDataGModel::getMax(int step)
{
if(step < 0) return _max;
if(step < _nodeData.size() && _nodeData[step]) return _nodeData[step]->max;
if(step < (int)_nodeData.size() && _nodeData[step]) return _nodeData[step]->max;
return 0.;
}
......@@ -142,12 +142,12 @@ bool PViewDataGModel::skipEntity(int ent)
bool PViewDataGModel::skipElement(int ent, int ele, int step)
{
if(step >= _nodeData.size() || !_nodeData[step]) return true;
if(step >= (int)_nodeData.size() || !_nodeData[step]) return true;
MElement *e = _entities[ent]->getMeshElement(ele);
if(!e->getVisibility()) return true;
for(int i = 0; i < e->getNumVertices(); i++){
int index = e->getVertex(i)->getDataIndex();
if(index < 0 || index >= _nodeData[step]->values.size()) return true;
if(index < 0 || index >= (int)_nodeData[step]->values.size()) return true;
if(_nodeData[step]->values[index].empty()) return true;
}
return false;
......@@ -155,8 +155,8 @@ bool PViewDataGModel::skipElement(int ent, int ele, int step)
bool PViewDataGModel::hasTimeStep(int step)
{
if(step < _nodeData.size() && _nodeData[step]) return true;
if(step < _elementData.size() && _elementData[step]) return true;
if(step < (int)_nodeData.size() && _nodeData[step]) return true;
if(step < (int)_elementData.size() && _elementData[step]) return true;
return false;
}
......
......@@ -28,12 +28,10 @@
template<class real>
class stepData{
public:
std::string fileName; // we allow to read steps from different files
int fileIndex;
double time, min, max;
// vector of data, indexed by dataIndex
std::vector<std::vector<real> > values;
stepData() : fileIndex(0), time(0.), min(VAL_INF), max(-VAL_INF){}
stepData() : time(0.), min(VAL_INF), max(-VAL_INF){}
~stepData() {}
};
......@@ -52,8 +50,6 @@ class PViewDataGModel : public PViewData {
SBoundingBox3d _bbox;
// a set of all "partitions" encountered in the input data
std::set<int> _partitions;
// create old-style list-based dataset from this one
PViewDataList *_cloneToList();
public:
PViewDataGModel(GModel *model);
~PViewDataGModel();
......@@ -76,6 +72,9 @@ class PViewDataGModel : public PViewData {
bool hasTimeStep(int step);
bool hasPartition(int part);
// create old-style list-based dataset from this one
//PViewDataList *convertToPViewDataList();
// I/O routines
bool readMSH(FILE *fp, bool binary, bool swap, int timeStep, double time,
int partition, int numComp, int numNodes);
......
// $Id: PViewDataGModelIO.cpp,v 1.5 2008-03-10 16:01:16 geuzaine Exp $
// $Id: PViewDataGModelIO.cpp,v 1.6 2008-03-10 19:59:01 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -35,7 +35,7 @@ bool PViewDataGModel::readMSH(FILE *fp, bool binary, bool swap, int timeStep,
Msg(INFO, "Reading step %d (time %g) partition %d: %d nodes",
timeStep, time, partition, numNodes);
while(timeStep >= _nodeData.size()) _nodeData.push_back(0);
while(timeStep >= (int)_nodeData.size()) _nodeData.push_back(0);
if(!_nodeData[timeStep]) _nodeData[timeStep] = new stepData<double>();
......@@ -64,10 +64,10 @@ bool PViewDataGModel::readMSH(FILE *fp, bool binary, bool swap, int timeStep,
v->setDataIndex(max + 1);
}
int index = v->getDataIndex();
if(index >= _nodeData[timeStep]->values.size())
if(index >= (int)_nodeData[timeStep]->values.size())
_nodeData[timeStep]->values.resize(index + 100); // optimize this
if(binary){
if(fread(&tmp[0], sizeof(double), numComp, fp) != numComp) return false;
if((int)fread(&tmp[0], sizeof(double), numComp, fp) != numComp) return false;
if(swap) swapBytes((char*)&tmp[0], sizeof(double), numComp);
}
else{
......@@ -124,7 +124,7 @@ bool PViewDataGModel::writeMSH(std::string name, bool binary)
fprintf(fp, "\"%s\"\n", getName().c_str());
fprintf(fp, "%d %.16g 0 0 %d %d\n", ts, _nodeData[ts]->time, numComp, numNodes);
for(unsigned int i = 0; i < _nodeData[ts]->values.size(); i++){
if(_nodeData[ts]->values[i].size() >= numComp){
if((int)_nodeData[ts]->values[i].size() >= numComp){
if(binary){
fwrite(&tags[i], sizeof(int), 1, fp);
fwrite(&_nodeData[ts]->values[i][0], sizeof(double), numComp, fp);
......
// $Id: PViewDataListIO.cpp,v 1.15 2008-03-10 16:01:17 geuzaine Exp $
// $Id: PViewDataListIO.cpp,v 1.16 2008-03-10 19:59:01 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -584,7 +584,6 @@ bool PViewDataList::writeMSH(std::string name, bool binary)
writeElementsMSH(fp, NbTY, TY, 5, 9, 3, &nodes, &numelm);
fprintf(fp, "$EndElements\n");
#if 1 // test new node-based storage
int numNodes = nodes.size();
if(numNodes){
int numComp = nodes.begin()->Val.size() / NbTimeStep;
......@@ -603,7 +602,6 @@ bool PViewDataList::writeMSH(std::string name, bool binary)
fprintf(fp, "$EndNodeData\n");
}
}
#endif
fclose(fp);
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment