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

added Element+ElementNode support in MSH format

parent 8484b79f
No related branches found
No related tags found
No related merge requests found
// $Id: PViewDataGModel.cpp,v 1.46 2008-04-02 16:30:29 geuzaine Exp $
// $Id: PViewDataGModel.cpp,v 1.47 2008-04-03 07:48:54 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -27,8 +27,8 @@
#include "Numeric.h"
#include "Message.h"
PViewDataGModel::PViewDataGModel()
: _min(VAL_INF), _max(-VAL_INF), _type(NodeData)
PViewDataGModel::PViewDataGModel(DataType type)
: _min(VAL_INF), _max(-VAL_INF), _type(type)
{
}
......
......@@ -143,7 +143,7 @@ class PViewDataGModel : public PViewData {
// the type of the dataset
DataType _type;
public:
PViewDataGModel();
PViewDataGModel(DataType type=NodeData);
~PViewDataGModel();
bool finalize();
int getNumTimeSteps();
......@@ -170,9 +170,8 @@ class PViewDataGModel : public PViewData {
bool hasMultipleMeshes();
bool useGaussPoints(){ return _type == GaussPointData; }
// get/set the data type
// get the data type
DataType getType(){ return _type; }
void setType(DataType type){ _type = type; }
// direct access to GModel entities
GEntity *getEntity(int step, int ent);
// direct access to value by index
......
// $Id: PViewDataGModelIO.cpp,v 1.36 2008-04-02 20:00:38 geuzaine Exp $
// $Id: PViewDataGModelIO.cpp,v 1.37 2008-04-03 07:48:54 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -32,10 +32,10 @@
bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp,
bool binary, bool swap, int step, double time,
int partition, int numComp, int numNodes)
int partition, int numComp, int numEnt)
{
Msg(INFO, "Reading step %d (time %g) partition %d: %d nodes",
step, time, partition, numNodes);
Msg(INFO, "Reading step %d (time %g) partition %d: %d records",
step, time, partition, numEnt);
while(step >= (int)_steps.size())
_steps.push_back(new stepData<double>(GModel::current(), numComp));
......@@ -50,9 +50,9 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp,
numSteps += _steps[i]->getNumData() ? 1 : 0;
if(numSteps > maxSteps) return true;
_steps[step]->resizeData(numNodes);
_steps[step]->resizeData(numEnt);
for(int i = 0; i < numNodes; i++){
for(int i = 0; i < numEnt; i++){
int num;
if(binary){
if(fread(&num, sizeof(int), 1, fp) != 1) return false;
......@@ -61,18 +61,31 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp,
else{
if(fscanf(fp, "%d", &num) != 1) return false;
}
double *d = _steps[step]->getData(num, true);
int mult = 1;
if(_type == ElementNodeData || _type == GaussPointData){
if(binary){
if(fread(&mult, sizeof(int), 1, fp) != 1) return false;
if(swap) swapBytes((char*)&mult, sizeof(int), 1);
}
else{
if(fscanf(fp, "%d", &mult) != 1) return false;
}
}
double *d = _steps[step]->getData(num, true, mult);
if(binary){
if((int)fread(d, sizeof(double), numComp, fp) != numComp) return false;
if(swap) swapBytes((char*)d, sizeof(double), numComp);
if((int)fread(d, sizeof(double), numComp * mult, fp) != numComp * mult)
return false;
if(swap) swapBytes((char*)d, sizeof(double), numComp * mult);
}
else{
for(int j = 0; j < numComp; j++)
for(int j = 0; j < numComp * mult; j++)
if(fscanf(fp, "%lf", &d[j]) != 1) return false;
}
double s = ComputeScalarRep(numComp, d);
_steps[step]->setMin(std::min(_steps[step]->getMin(), s));
_steps[step]->setMax(std::max(_steps[step]->getMax(), s));
for(int j = 0; j < mult; j++){
double s = ComputeScalarRep(numComp, &d[numComp *j]);
_steps[step]->setMin(std::min(_steps[step]->getMin(), s));
_steps[step]->setMax(std::max(_steps[step]->getMax(), s));
}
}
_partitions.insert(partition);
......@@ -90,6 +103,11 @@ bool PViewDataGModel::writeMSH(std::string fileName, bool binary)
return false;
}
if(_type != NodeData){
Msg(GERROR, "Can only export node-based datasets for now");
return false;
}
GModel *model = _steps[0]->getModel();
binary = true;
......@@ -217,9 +235,8 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
}
else{
med_entite_maillage ent = entType[pairs[0].first];
setType((ent == MED_NOEUD) ? NodeData :
(ent == MED_MAILLE) ? ElementData :
ElementNodeData);
_type = (ent == MED_NOEUD) ? NodeData : (ent == MED_MAILLE) ? ElementData :
ElementNodeData;
}
for(int step = 0; step < numSteps; step++){
......@@ -263,7 +280,7 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
}
else if(ngauss != MED_NOPG){
mult = ngauss;
setType(GaussPointData);
_type = GaussPointData;
}
_steps[step]->resizeData(numVal / mult);
......
// $Id: PViewIO.cpp,v 1.3 2008-03-29 10:19:43 geuzaine Exp $
// $Id: PViewIO.cpp,v 1.4 2008-04-03 07:48:54 geuzaine Exp $
//
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
......@@ -145,25 +145,34 @@ bool PView::readMSH(std::string fileName, int fileIndex)
}
}
}
else if(!strncmp(&str[1], "NodeData", 8)) {
else if(!strncmp(&str[1], "NodeData", 8) ||
!strncmp(&str[1], "ElementData", 11) ||
!strncmp(&str[1], "ElementNodeData", 15)) {
index++;
if(fileIndex < 0 || fileIndex == index){
PViewDataGModel::DataType type;
if(!strncmp(&str[1], "NodeData", 8))
type = PViewDataGModel::NodeData;
else if(!strncmp(&str[1], "ElementData", 11))
type = PViewDataGModel::ElementData;
else
type = PViewDataGModel::ElementNodeData;
// read data info
if(!fgets(str, sizeof(str), fp)) return false;
std::string name = extractDoubleQuotedString(str, sizeof(str));
int timeStep, partition, interpolationScheme, numComp, numNodes;
int timeStep, partition, interpolationScheme, numComp, numEnt;
double time;
if(!fgets(str, sizeof(str), fp)) return false;
if(sscanf(str, "%d %lf %d %d %d %d", &timeStep, &time, &partition,
&interpolationScheme, &numComp, &numNodes) != 6) return false;
&interpolationScheme, &numComp, &numEnt) != 6) return false;
// either get existing viewData, or create new one
PView *p = getViewByName(name, timeStep, partition);
PViewDataGModel *d = 0;
if(p) d = dynamic_cast<PViewDataGModel*>(p->getData());
bool create = d ? false : true;
if(create) d = new PViewDataGModel();
if(create) d = new PViewDataGModel(type);
if(!d->readMSH(fileName, fileIndex, fp, binary, swap, timeStep,
time, partition, numComp, numNodes)){
time, partition, numComp, numEnt)){
Msg(GERROR, "Could not read data in msh file");
if(create) delete d;
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment