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

more work on MED IO

parent ffd9c0cb
No related branches found
No related tags found
No related merge requests found
// $Id: PViewDataGModel.cpp,v 1.38 2008-03-29 23:40:56 geuzaine Exp $ // $Id: PViewDataGModel.cpp,v 1.39 2008-03-30 10:25:09 geuzaine Exp $
// //
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
// //
...@@ -166,7 +166,11 @@ void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, do ...@@ -166,7 +166,11 @@ void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, do
val = _steps[step]->getData(v->getNum())[comp]; val = _steps[step]->getData(v->getNum())[comp];
} }
else{ else{
Msg(GERROR, "Element-based data sets not yet ready!"); MElement *e = _steps[step]->getEntity(ent)->getMeshElement(ele);
if(_type == ElementData)
val = _steps[step]->getData(e->getNum())[comp];
else
Msg(GERROR, "ElementNode data not ready yet!");
} }
} }
......
...@@ -91,11 +91,11 @@ class stepData{ ...@@ -91,11 +91,11 @@ class stepData{
if(!_data) _data = new std::vector<real*>(n, (real*)0); if(!_data) _data = new std::vector<real*>(n, (real*)0);
if(n > (int)_data->size()) _data->resize(n, (real*)0); if(n > (int)_data->size()) _data->resize(n, (real*)0);
} }
real *getData(int index, bool allocIfNeeded=false) real *getData(int index, bool allocIfNeeded=false, int mult=1)
{ {
if(allocIfNeeded){ if(allocIfNeeded){
if(index >= getNumData()) resizeData(index + 100); // optimize this if(index >= getNumData()) resizeData(index + 100); // optimize this
if(!(*_data)[index]) (*_data)[index] = new real[_numComp]; if(!(*_data)[index]) (*_data)[index] = new real[_numComp * mult];
} }
else{ else{
if(index >= getNumData()) return 0; if(index >= getNumData()) return 0;
......
// $Id: PViewDataGModelIO.cpp,v 1.20 2008-03-29 23:40:56 geuzaine Exp $ // $Id: PViewDataGModelIO.cpp,v 1.21 2008-03-30 10:25:09 geuzaine Exp $
// //
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
// //
...@@ -146,19 +146,6 @@ extern "C" { ...@@ -146,19 +146,6 @@ extern "C" {
#include <med.h> #include <med.h>
} }
static void fillData(stepData<double> *data, int dataIndex,
std::vector<double> &val, int valIndex, int numComp)
{
double *d = data->getData(dataIndex, true);
for(int j = 0; j < numComp; j++)
d[j] = val[numComp * valIndex + j];
for(int j = numComp; j < data->getNumComponents(); j++)
d[j] = 0.;
double s = ComputeScalarRep(data->getNumComponents(), d);
data->setMin(std::min(data->getMin(), s));
data->setMax(std::max(data->getMax(), s));
}
bool PViewDataGModel::readMED(std::string fileName, int fileIndex) bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
{ {
med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE); med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE);
...@@ -183,17 +170,23 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) ...@@ -183,17 +170,23 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
return false; return false;
} }
Msg(INFO, "Reading %d-component field <<%s>>\n", numComp, name); Msg(INFO, "Reading %d-component field <<%s>>", numComp, name);
setName(name); setName(name);
// the ordering of the elements in the following lists is important:
// it should match the ordering of the MSH element types (when
// elements are saved without tags, this governs the order with
// which we implicitly index them in GModel::readMED)
const med_entite_maillage entType[] = const med_entite_maillage entType[] =
{MED_NOEUD, MED_MAILLE, MED_NOEUD_ELEMENT}; {MED_NOEUD, MED_MAILLE, MED_NOEUD_ELEMENT};
// don't import points for now (points are not numbered in the same
// sequence as MElements)
const med_geometrie_element eleType[] = const med_geometrie_element eleType[] =
{MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8, MED_PENTA6, {MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8,
MED_PYRA5, MED_SEG3, MED_TRIA6, MED_TETRA10, MED_POINT1, MED_QUAD8, MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_TETRA10,
MED_HEXA20, MED_PENTA15, MED_PYRA13}; /* MED_POINT1, */ MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13};
const int nodesPerEle[] = const int nodesPerEle[] =
{0, 2, 3, 4, 4, 8, 6, 5, 3, 6, 10, 1, 8, 20, 15, 13}; {0, 2, 3, 4, 4, 8, 6, 5, 3, 6, 10, /* 1, */ 8, 20, 15, 13};
med_int numSteps = 0; med_int numSteps = 0;
std::vector<std::pair<int, int> > pairs; std::vector<std::pair<int, int> > pairs;
...@@ -219,15 +212,11 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) ...@@ -219,15 +212,11 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
ElementNodeData); ElementNodeData);
} }
_steps.clear();
for(int step = 0; step < numSteps; step++){ for(int step = 0; step < numSteps; step++){
int numCompGmsh = (numComp == 2) ? 3 : numComp; int eleIndex = 0;
_steps.push_back(new stepData<double>(GModel::current(), numCompGmsh));
_steps.back()->setFileName(fileName);
_steps.back()->setFileIndex(fileIndex);
}
for(int step = 0; step < numSteps; step++){
for(unsigned int pair = 0; pair < pairs.size(); pair++){ for(unsigned int pair = 0; pair < pairs.size(); pair++){
// get step info
med_entite_maillage ent = entType[pairs[pair].first]; med_entite_maillage ent = entType[pairs[pair].first];
med_geometrie_element ele = eleType[pairs[pair].second]; med_geometrie_element ele = eleType[pairs[pair].second];
med_int numdt, numo, ngauss, numMeshes; med_int numdt, numo, ngauss, numMeshes;
...@@ -236,27 +225,43 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) ...@@ -236,27 +225,43 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
med_booleen local; med_booleen local;
if(MEDpasdetempsInfo(fid, name, ent, ele, step + 1, &ngauss, &numdt, &numo, if(MEDpasdetempsInfo(fid, name, ent, ele, step + 1, &ngauss, &numdt, &numo,
dtunit, &dt, meshName, &local, &numMeshes) < 0){ dtunit, &dt, meshName, &local, &numMeshes) < 0){
Msg(GERROR, "Could not get step info"); Msg(GERROR, "Could not read step info");
return false; return false;
} }
// create step data
if(!pair){
int numCompMsh = (numComp == 1) ? 1 : (numComp < 3) ? 3 : 9;
while(step >= (int)_steps.size())
_steps.push_back(new stepData<double>(GModel::current(), numCompMsh));
_steps[step]->setFileName(fileName);
_steps[step]->setFileIndex(fileIndex);
_steps[step]->setTime(dt); _steps[step]->setTime(dt);
}
med_int numVal = MEDnVal(fid, name, ent, ele, numdt, numo, // get number of values in the field (numVal takes the number of
meshName, MED_COMPACT); // Gauss points or the number of nodes per element into account,
// but not the number of components)
med_int numVal = MEDnVal(fid, name, ent, ele, numdt, numo, meshName,
MED_COMPACT);
if(numVal <= 0) continue; if(numVal <= 0) continue;
_steps[step]->resizeData(numVal);
int mult = 1; int mult = 1;
if(ent == MED_NOEUD_ELEMENT) mult = nodesPerEle[pairs[pair].second]; if(getType() == ElementNodeData) mult = nodesPerEle[pairs[pair].second];
std::vector<double> val(numVal * numComp * mult); if(ngauss) mult *= ngauss;
// only a guess, since several element types may be combined
_steps[step]->resizeData(numVal / mult);
// read field data
std::vector<double> val(numVal * numComp);
char locname[MED_TAILLE_NOM + 1], profileName[MED_TAILLE_NOM + 1]; char locname[MED_TAILLE_NOM + 1], profileName[MED_TAILLE_NOM + 1];
if(MEDchampLire(fid, meshName, name, (unsigned char*)&val[0], MED_FULL_INTERLACE, if(MEDchampLire(fid, meshName, name, (unsigned char*)&val[0], MED_FULL_INTERLACE,
MED_ALL, locname, profileName, MED_COMPACT, ent, ele, MED_ALL, locname, profileName, MED_COMPACT, ent, ele,
numdt, numo) < 0){ numdt, numo) < 0){
Msg(GERROR, "Could not get field values"); Msg(GERROR, "Could not read field values");
return false; return false;
} }
// compute profile (indices in full array of entities of given type)
std::vector<med_int> profile; std::vector<med_int> profile;
if(std::string(profileName) != MED_NOPFL){ if(std::string(profileName) != MED_NOPFL){
med_int n = MEDnValProfil(fid, profileName); med_int n = MEDnValProfil(fid, profileName);
...@@ -269,32 +274,49 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) ...@@ -269,32 +274,49 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
} }
} }
if(profile.empty()){ if(profile.empty()){
profile.resize(numVal); profile.resize(numVal / mult);
for(int i = 0; i < numVal; i++) for(unsigned int i = 0; i < profile.size(); i++)
profile[i] = i + 1; profile[i] = i + 1;
} }
if(ent == MED_NOEUD){ // get size of full array and tags (if any) of entities
med_int numNodes = MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, bool nodal = (ent == MED_NOEUD);
MED_NONE, (med_connectivite)0); med_int numEnt = MEDnEntMaa(fid, meshName, nodal ? MED_COOR : MED_CONN,
std::vector<med_int> nodeTags(numNodes); nodal ? MED_NOEUD : MED_MAILLE,
if(MEDnumLire(fid, meshName, &nodeTags[0], numNodes, MED_NOEUD, MED_NONE) < 0) nodal ? MED_NONE : ele,
nodeTags.clear(); nodal ? (med_connectivite)0 : MED_NOD);
std::vector<med_int> tags(numEnt);
if(MEDnumLire(fid, meshName, &tags[0], numEnt, nodal ? MED_NOEUD : MED_MAILLE,
nodal ? MED_NONE : ele) < 0)
tags.clear();
// compute entity numbers using profile, then fill step data
for(unsigned int i = 0; i < profile.size(); i++){ for(unsigned int i = 0; i < profile.size(); i++){
int num = nodeTags.empty() ? profile[i] : nodeTags[profile[i] - 1]; int num;
fillData(_steps[step], num, val, i, numComp); if(tags.empty()){
} num = profile[i];
if(!nodal) num += eleIndex;
} }
else{ else{
Msg(GERROR, "Element-based MED import not ready yet!"); if(profile[i] == 0 || profile[i] > tags.size()){
// TODO... PS: since MED index elements by subgroups of Msg(GERROR, "Wrong index in profile");
// elements of the same type, we need to define an order of Msg(DEBUG, "nodal=%d prof[%d]=%d #prof=%d #tags=%d numVal=%d mult=%d",
// element types in stepData and STICK WITH IT! We need a nodal, i, profile[i], profile.size(), tags.size(), numVal, mult);
// single routine to compute element order and indices, which return false;
// can also map to element numbers (+ deal with special case }
// for points) num = tags[profile[i] - 1];
}
double *d = _steps[step]->getData(num, true, mult);
for(int j = 0; j < numComp * mult; j++)
d[j] = val[numComp * i + j];
for(int j = numComp; j < _steps[step]->getNumComponents(); j++)
d[j] = 0.;
double s = ComputeScalarRep(_steps[step]->getNumComponents(), d);
_steps[step]->setMin(std::min(_steps[step]->getMin(), s));
_steps[step]->setMax(std::max(_steps[step]->getMax(), s));
} }
if(!nodal) eleIndex += numEnt;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment