#include "VISU_MedConvertor.hxx"
-#include <valarray>
+#include "VISU_Convertor.hxx"
+#include "VISU_ConvertorUtils.hxx"
+
+#include "MED_Factory.hxx"
+#include "MED_Algorithm.hxx"
+#include "MED_Utilities.hxx"
+
#include <vtkCellType.h>
-#define USER_INTERLACE MED_FULL_INTERLACE
+
+#define _EDF_NODE_IDS_
using namespace std;
+using namespace MED;
+using namespace VISU;
#ifdef _DEBUG_
static int MYDEBUG = 0;
static int MYDEBUG = 0;
#endif
-static med_err ret = 0;
-typedef map<VISU::TEntity,med_entite_maillage> TVisu2MedEntity;
+namespace{
-static TVisu2MedEntity aVisu2MedEntity;
-
-static int INIT = (
- aVisu2MedEntity[VISU::NODE_ENTITY] = MED_NOEUD,
- aVisu2MedEntity[VISU::EDGE_ENTITY] = MED_ARETE,
- aVisu2MedEntity[VISU::FACE_ENTITY] = MED_FACE,
- aVisu2MedEntity[VISU::CELL_ENTITY] = MED_MAILLE,
- 1);
+ using namespace MED;
+ using namespace VISU;
+
+ int MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
+ {
+ return theMEDGeomType % 100;
+ }
-static med_geometrie_element NODEGEOM[1] = {MED_POINT1};
+ int MEDGeomToVTK(MED::EGeometrieElement theMEDGeomType)
+ {
+ switch(theMEDGeomType){
+ case ePOINT1: return VTK_VERTEX;
+ case eSEG2: return VTK_LINE;
+ case eSEG3: return VTK_LINE;
+ case eTRIA3: return VTK_TRIANGLE;
+ case eTRIA6: return VTK_TRIANGLE;
+ case eQUAD4: return VTK_QUAD;
+ case eQUAD8: return VTK_QUAD;
+ case eTETRA4: return VTK_TETRA;
+ case eTETRA10: return VTK_TETRA;
+ case eHEXA8: return VTK_HEXAHEDRON;
+ case eHEXA20: return VTK_HEXAHEDRON;
+ case ePENTA6: return VTK_WEDGE;
+ case ePENTA15: return VTK_WEDGE;
+ case ePYRA5: return VTK_PYRAMID;
+ case ePYRA13: return VTK_PYRAMID;
+ case ePOLYGONE: return VTK_POLYGON;
+ case ePOLYEDRE: return VTK_CONVEX_POINT_SET;
+ }
+ return -1;
+ }
-static med_geometrie_element EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
- MED_SEG2, MED_SEG3
- };
+ int VTKGeom2NbNodes(int theVTKGeomType)
+ {
+ switch(theVTKGeomType){
+ case VTK_VERTEX: return 1;
+ case VTK_LINE: return 2;
+ case VTK_TRIANGLE: return 3;
+ case VTK_QUAD: return 4;
+ case VTK_TETRA: return 4;
+ case VTK_HEXAHEDRON: return 8;
+ case VTK_WEDGE: return 6;
+ case VTK_PYRAMID: return 5;
+ }
+ return -1;
+ }
-static med_geometrie_element FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
- MED_TRIA3, MED_QUAD4, MED_TRIA6, MED_QUAD8
- };
+ MED::EGeometrieElement VTKGeomToMED(int theVTKGeomType)
+ {
+ switch(theVTKGeomType){
+ case VTK_VERTEX: return ePOINT1;
+ case VTK_LINE: return eSEG2;
+ case VTK_TRIANGLE: return eTRIA3;
+ case VTK_QUAD: return eQUAD4;
+ case VTK_TETRA: return eTETRA4;
+ case VTK_HEXAHEDRON: return eHEXA8;
+ case VTK_WEDGE: return ePENTA6;
+ case VTK_PYRAMID: return ePYRA5;
+ case VTK_POLYGON: return ePOLYGONE;
+ case VTK_CONVEX_POINT_SET: return ePOLYEDRE;
+ }
+ return EGeometrieElement(-1);
+ }
-static med_geometrie_element CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
- MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3,
- MED_QUAD4, MED_TRIA6, MED_QUAD8, MED_TETRA4,
- MED_PYRA5, MED_PENTA6, MED_HEXA8, MED_TETRA10,
- MED_PYRA13, MED_PENTA15, MED_HEXA20
- };
+ TEntity MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
+ {
+ switch(theMEDEntity){
+ case eNOEUD: return NODE_ENTITY;
+ case eARETE: return EDGE_ENTITY;
+ case eFACE: return FACE_ENTITY;
+ case eMAILLE: return CELL_ENTITY;
+ }
+ return TEntity(-1);
+ }
-void GetEntity2Geom(const VISU::TEntity& theEntity, med_geometrie_element*& theVector, int* theEnd)
- throw (std::runtime_error&)
-{
- switch(theEntity){
- case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
- case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
- case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
- case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
- default:
- throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect");
+ MED::EEntiteMaillage VTKEntityToMED(TEntity theVTKEntity)
+ {
+ switch(theVTKEntity){
+ case NODE_ENTITY: return eNOEUD;
+ case EDGE_ENTITY: return eARETE;
+ case FACE_ENTITY: return eFACE;
+ case CELL_ENTITY: return eMAILLE;
+ }
+ return MED::EEntiteMaillage(-1);
}
+
}
extern "C"
-VISU_Convertor* CreateMedConvertor(const string& theFileName) throw(std::runtime_error&){
+VISU_Convertor* CreateConvertor(const string& theFileName)
+{
return new VISU_MedConvertor(theFileName);
}
-class MedFile{
- char* myFileName;
- med_idt myFid;
- MedFile();
- MedFile(const MedFile&);
-public:
- MedFile(const char* theFileName) throw(std::runtime_error&) :
- myFileName(strdup(theFileName))
- {
- myFid = MEDouvrir(myFileName,MED_LECT);
- if(myFid < 0){
- free(myFileName);
- throw std::runtime_error(string("MedFile::MedFile >> MEDouvrir(...) - ") + theFileName);
- }
- }
- ~MedFile(){
- free(myFileName);
- if(myFid >= 0)
- MEDfermer(myFid);
- }
- const med_idt& GetFid() const { return myFid;};
-};
-
-VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) throw (std::runtime_error&) {
+VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) {
myFileInfo.setFile(QString(theFileName.c_str()));
myName = myFileInfo.baseName().latin1();
}
-VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) {
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- med_int iMeshEnd = MEDnMaa(fid); //Get number of meshes
- if(MYDEBUG) MESSAGE("ImportInfo - MEDnMaa = "<<iMeshEnd<<"; myFileInfo = "<<myFileInfo.filePath());
- for(int iMesh = 1; iMesh <= iMeshEnd; iMesh++){
- med_int aMeshDim;
- char aMeshName[MED_TAILLE_NOM+1] = "";
- MEDmaaInfo(fid,iMesh,aMeshName,&aMeshDim);
- if(MYDEBUG) MESSAGE("ImportInfo - aMeshName = '"<<aMeshName<<"'; aMeshDim = "<<aMeshDim);
- VISU::TMesh &aMesh = myMeshMap[aMeshName];
- aMesh.myDim = aMeshDim;
- aMesh.myName = aMeshName;
- typedef map<med_int,VISU::TEntity> TFamily2EntityMap;
- TFamily2EntityMap aFamily2EntityMap;
- typedef map<med_int,med_int> TFamilyCounterMap;
+VISU_Convertor* VISU_MedConvertor::Build() {
+ PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
+ TInt aNbMeshes = aMed->GetNbMeshes();
+ TMeshMap& aMeshMap = myMeshMap;
+
+ MSG(MYDEBUG,"VISU_MedConvertor::Build()");
+ INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<"\n");
+
+ for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++)
+ try{
+ PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
+
+ PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
+
+ MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
+
+ TElemGroup aElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
+
+ TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
+
+ TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aElemGroup,aFamilyGroup);
+
+ TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
+
+ // creating TMesh structure and TMeshOnEntityMap
+ typedef map<TInt,TInt> TFamilyCounterMap;
TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap;
- TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
- for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) {
- VISU::TEntity anEntity = aVisu2MedEntityIter->first;
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- int medId = getIdMedType(aGeomElemVector[iGeomElem]);
- int aVtkType = med2vtk[medId].vtkType;
- med_geometrie_element aMedType = med2vtk[medId].medType;
- if(aMedEntity == MED_NOEUD){
- med_geometrie_element typgeo = (med_geometrie_element)0;
- med_connectivite typco = (med_connectivite)0;
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,typgeo,typco);
- if(iNumElemEnd > 0){
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- aMeshOnEntity.myEntity = anEntity;
- aMeshOnEntity.myMeshName = aMeshName;
- aMeshOnEntity.myNbCells = iNumElemEnd;
- aMeshOnEntity.myCellsSize = 2*iNumElemEnd;
- aMesh.myNbPoints = iNumElemEnd;
- if(MYDEBUG)
- MESSAGE("ImportInfo -\t anEntity = "<<anEntity<<
- "; medName = "<<med2vtk[medId].medName<<
- "; myNbCells = "<<aMeshOnEntity.myNbCells<<
- "; myCellsSize = "<<aMeshOnEntity.myCellsSize);
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_repere rep;
- valarray<char> name_coord('\0',aMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<char> unit_coord('\0',aMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<med_float> coord(aMesh.myDim*iNumElemEnd);
- ret = MEDnoeudsLire(fid,aMeshName,aMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
- &name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
- &num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDnoeudsLire(...)");
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] != 0){
- aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
- aFamilyNbCellsCounterMap[num_fam_elem[iNumElem]] += 1;
- aFamilyCellsSizeCounterMap[num_fam_elem[iNumElem]] += 2;
- }
+
+ TInt aDim = aMeshInfo->GetDim();
+ const string& aMeshName = aMeshInfo->GetName();
+
+ PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh());
+ aMesh->myDim = aDim;
+ aMesh->myName = aMeshName;
+ aMesh->myNbPoints = aNodeInfo->GetNbElem();
+ aMesh->myMeshInfo = aMeshInfo;
+ aMesh->myEntityInfo = aEntityInfo;
+
+ INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
+ "'; myNbPoints = "<<aMesh->myNbPoints<<
+ "; aDim = "<<aDim<<"\n");
+
+ BEGMSG(MYDEBUG,"aEntityInfo.size() = "<<aEntityInfo.size()<<"\n");
+
+ TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+ MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
+ for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
+ const EEntiteMaillage& aMEntity = anEntityIter->first;
+ const MED::TGeom& aTGeom = anEntityIter->second;
+
+ TEntity aVEntity = MEDEntityToVTK(aMEntity);
+ PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity());
+ aMeshOnEntity->myEntity = aVEntity;
+ aMeshOnEntity->myMeshName = aMeshName;
+ aMeshOnEntity->myGeom = aTGeom;
+
+ INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
+
+ if(aMEntity == eNOEUD){
+ aMeshOnEntity->myNbCells = aMesh->myNbPoints;
+ aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints;
+
+ for(TInt iElem = 0; iElem < aMesh->myNbPoints; iElem++){
+ TInt aFamId = aNodeInfo->GetFamNum(iElem);
+ if(aFamId != 0){
+ aFamilyNbCellsCounterMap[aFamId] += 1;
+ aFamilyCellsSizeCounterMap[aFamId] += 2;
}
}
- //Get number of connectivities
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aMedType,MED_NOD);
- if (iNumElemEnd > 0) {
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- aMeshOnEntity.myEntity = anEntity;
- aMeshOnEntity.myMeshName = aMeshName;
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim);
- aMeshOnEntity.myNbCells += iNumElemEnd;
- aMeshOnEntity.myCellsSize += iNumElemEnd*(med2vtk[medId].vtkNbNodes + 1);
- if(MYDEBUG)
- MESSAGE("ImportInfo -\t anEntity = "<<anEntity<<
- "; medName = "<<med2vtk[medId].medName<<
- "; aNbConnForElem = "<<aNbConnForElem<<
- "; myNbCells = "<<aMeshOnEntity.myNbCells<<
- "; myCellsSize = "<<aMeshOnEntity.myCellsSize);
- valarray<med_int> conn(0,aNbConnForElem*iNumElemEnd);
- ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
- &name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
- &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("ImportInfo >> MEDelementsLire(...)");
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] != 0){
- aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
- aFamilyNbCellsCounterMap[num_fam_elem[iNumElem]] += 1;
- aFamilyCellsSizeCounterMap[num_fam_elem[iNumElem]] += med2vtk[medId].vtkNbNodes + 1;
- }
+
+ INITMSG(MYDEBUG,"myNbCells = "<<aMeshOnEntity->myNbCells<<
+ "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");;
+
+ }else{
+ MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+ aMeshOnEntity->myNbCells = 0;
+ aMeshOnEntity->myCellsSize = 0;
+ for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+ const EGeometrieElement& aGeom = anTGeomIter->first;
+
+ switch(aGeom){
+ case ePOLYGONE:
+ {
+ PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aPolygoneInfo->GetNbElem();
+ TElemNum aConn = aPolygoneInfo->GetConnectivite();
+ TElemNum aIndex = aPolygoneInfo->GetIndex();
+ TInt aNbIndex = aIndex.size();
+ TInt aNbConn = aConn.size();
+
+ aMeshOnEntity->myNbCells += aNbElem;
+
+ for (int ii = 0; ii<aNbElem ; ii++){
+ int aNbConnii = aPolygoneInfo->GetNbConn(ii);
+ aMeshOnEntity->myCellsSize += aNbConnii;
+ }
+ INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
+ "; myNbPolygones = "<<aNbElem<<
+ "; nbConn= "<<aNbConn<<"\n");
+
+ for(TInt iElem = 0; iElem < aNbElem; iElem++){
+ TInt aFamId = aPolygoneInfo->GetFamNum(iElem);
+ if(aFamId != 0){
+ aFamilyNbCellsCounterMap[aFamId] += 1;
+ ADDMSG(MYDEBUG,"aFamId="<<aFamId<<" ");
+ aFamilyCellsSizeCounterMap[aFamId] += aPolygoneInfo->GetNbConn(iElem) + 1;
+ }
+ }
+ ADDMSG(MYDEBUG,endl);
+ break;
+ }
+ case ePOLYEDRE:
+ {
+ PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aPolyedreInfo->GetNbElem();
+ TElemNum aConn = aPolyedreInfo->GetConnectivite();
+ TElemNum aIndex = aPolyedreInfo->GetIndex();
+ TInt aNbIndex = aIndex.size();
+ TInt aNbConn = aConn.size();
+
+ aMeshOnEntity->myNbCells += aNbElem;
+
+ for (int ii = 0; ii<aNbElem ; ii++){
+ int aNbConnii = aPolyedreInfo->GetNbConn(ii);
+ aMeshOnEntity->myCellsSize += aNbConnii;
+ }
+ INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
+ "; myNbPolyedres = "<<aNbElem<<
+ "; nbConn= "<<aNbConn<<"\n");
+
+ for(TInt iElem = 0; iElem < aNbElem; iElem++){
+ TInt aFamId = aPolyedreInfo->GetFamNum(iElem);
+ std::string aName = aPolyedreInfo->GetElemName(iElem);
+ if(aFamId != 0){
+ aFamilyNbCellsCounterMap[aFamId] += 1;
+ ADDMSG(MYDEBUG,"(aFamId="<<aFamId<<";Name='"<<aName<<"') ");
+ aFamilyCellsSizeCounterMap[aFamId] += aPolyedreInfo->GetNbConn(iElem) + 1;
+ }
+ }
+ ADDMSG(MYDEBUG,endl);
+ break;
+ }
+ default:
+ {
+ int aVNbNodes = VTKGeom2NbNodes(MEDGeomToVTK(aGeom));
+ PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aCellInfo->GetNbElem();
+ aMeshOnEntity->myNbCells += aNbElem;
+ aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
+ INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
+ "; myNbCells = "<<aMeshOnEntity->myNbCells<<
+ "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");
+
+ for(TInt iElem = 0; iElem < aNbElem; iElem++){
+ TInt aFamId = aCellInfo->GetFamNum(iElem);
+ if(aFamId != 0){
+ aFamilyNbCellsCounterMap[aFamId] += 1;
+ ADDMSG(MYDEBUG,"aFamId = "<<aFamId<<" ");
+ aFamilyCellsSizeCounterMap[aFamId] += aVNbNodes + 1;
+ }
+ }
+ ADDMSG(MYDEBUG,endl);
+ }
+ } // end switch(...)
}
}
}
- med_int aNbFamily = MEDnFam(fid,aMeshName,0,MED_FAMILLE);
- if(MYDEBUG) MESSAGE("ImportInfo - aNbFamily = "<<aNbFamily);
- for(int aFamInd = 1; aFamInd <= aNbFamily; aFamInd++){
- med_int aNbAttrib = MEDnFam(fid,aMeshName,aFamInd,MED_ATTR);
- valarray<med_int> anAttId(aNbAttrib), anAttVal(aNbAttrib);
- valarray<char> anAttDesc('\0',aNbAttrib*MED_TAILLE_DESC+1);
- med_int aNbGroup = MEDnFam(fid,aMeshName,aFamInd,MED_GROUPE);
- if(0 && MYDEBUG)
- MESSAGE("ImportInfo - aFamInd = "<<aFamInd<<"; aNbAttrib = "<<aNbAttrib<<"; aNbGroup = "<<aNbGroup);
- valarray<char> aGroupNames('\0',aNbGroup*MED_TAILLE_LNOM+1);
- char aFamilyName[MED_TAILLE_NOM+1] = "";
- med_int aFamilyNum;
- ret = MEDfamInfo(fid,aMeshName,aFamInd,aFamilyName,&aFamilyNum,
- &anAttId[0],&anAttVal[0],&anAttDesc[0],&aNbAttrib,
- &aGroupNames[0],&aNbGroup);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDfamInfo");
- if(0 && MYDEBUG)
- MESSAGE("ImportInfo - aFamilyNum = "<<aFamilyNum<<"; aNbGroup = "<<aNbGroup);
- if(aFamily2EntityMap.find(aFamilyNum) == aFamily2EntityMap.end()) {
- if(MYDEBUG) MESSAGE("ImportInfo - a Family with name '"<<aFamilyName<<"' are empty !!!");
+
+ TFamilyByEntity::const_iterator aFamilyByEntityIter = aFamilyByEntity.begin();
+ BEGMSG(MYDEBUG,"TFamilyByEntity:\n");
+ for(; aFamilyByEntityIter != aFamilyByEntity.end(); aFamilyByEntityIter++){
+ const EEntiteMaillage& aMEntity = aFamilyByEntityIter->first;
+ const TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second;
+
+ TEntity aVEntity = MEDEntityToVTK(aMEntity);
+ VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
+ VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+
+ if(aFamilyGroup.empty())
continue;
- }
- VISU::TEntity anEntity = aFamily2EntityMap[aFamilyNum];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName];
- aFamily.myName = aFamilyName;
- aFamily.myEntity = anEntity;
- aFamily.myId = aFamilyNum;
- aFamily.myNbCells = aFamilyNbCellsCounterMap[aFamilyNum];
- aFamily.myCellsSize = aFamilyCellsSizeCounterMap[aFamilyNum];
- if(MYDEBUG)
- MESSAGE("ImportInfo - aFamily.myEntity = "<<anEntity<<
- "; myName = '"<<aFamilyName<<
- "'; myId = "<<aFamilyNum<<
- "; myNbCells = "<<aFamily.myNbCells<<
- "; myCellsSize = "<<aFamily.myCellsSize);
- VISU::TBindGroups& aBindGroups = aFamily.myGroups;
- for(int iGroup = 0, iPos = 0; iGroup < aNbGroup; iGroup++, iPos += MED_TAILLE_LNOM){
- char aGroupName[MED_TAILLE_LNOM+1];
- strncpy(aGroupName,&aGroupNames[iPos],MED_TAILLE_LNOM);
- aGroupName[MED_TAILLE_LNOM] = '\0';
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupName["<<iGroup<<"] = '"<<aGroupName<<"'");
- aBindGroups.insert(aGroupName);
- }
- }
- //Calculation of TMesh.TGroupMap
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- if(aMeshOnEntityMap.empty()) continue;
- VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
- if(aFamilyMap.empty()) continue;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
- for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
- const VISU::TFamily& aFamily = aFamilyMapIter->second;
- const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
- if(aBindGroups.empty()) continue;
- VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
- for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
- const string& aGroupName = *aBindGroupsIter;
- VISU::TGroup& aGroup = aGroupMap[aGroupName];
- aGroup.myName = aGroupName;
- aGroup.myMeshName = aMesh.myName;
- VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
- aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
- aGroup.myNbCells += aFamily.myNbCells;
- aGroup.myCellsSize += aFamily.myCellsSize;
+
+ INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
+ TFamilyGroup::const_iterator aFamilyGroupIter = aFamilyGroup.begin();
+ for(; aFamilyGroupIter != aFamilyGroup.end(); aFamilyGroupIter++){
+ const PFamilyInfo& aFamilyInfo = *aFamilyGroupIter;
+ if (aFamilyInfo->GetId() == 0)
+ continue;
+
+ const std::string& aFamilyName = aFamilyInfo->GetName();
+ PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
+
+ aFamily->myId = aFamilyInfo->GetId();
+ aFamily->myName = aFamilyInfo->GetName();
+ aFamily->myEntity = aVEntity;
+ aFamily->myNbCells = aFamilyNbCellsCounterMap[aFamily->myId];
+ aFamily->myCellsSize = aFamilyCellsSizeCounterMap[aFamily->myId];
+
+ INITMSG(MYDEBUG,"aFamilyName = '"<<aFamily->myName<<
+ "'; myId = "<<aFamily->myId<<"; "<<
+ "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
+ "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
+ "; myEntity = "<<aFamily->myEntity<<
+ "; myNbCells = "<<aFamily->myNbCells<<
+ "; myCellsSize = "<<aFamily->myCellsSize<<"\n");
+
+ VISU::TBindGroups& aBindGroups = aFamily->myGroups;
+ const TInt aNbGroup = aFamilyInfo->GetNbGroup();
+ for(TInt i = 0; i < aNbGroup; i++){
+ const string& aGroupName = aFamilyInfo->GetGroupName(i);
+ aBindGroups.insert(aGroupName);
+ INITMSG(MYDEBUG,"aGroupName = '"<<aGroupName<<"'\n");
}
}
}
- //Displaing information for the TMesh.TGroupMap
- VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupMap.size() = "<<aGroupMap.size());
- for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
- const VISU::TGroup& aCGroup = aGroupMapIter->second;
- const string& aGroupName = aGroupMapIter->first;
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupName = '"<<aGroupName<<
- "'; myNbCells = "<<aCGroup.myNbCells<<
- "; myCellsSize = "<<aCGroup.myCellsSize);
- const VISU::TGroup& aGroup = aGroupMapIter->second;
- const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet;
- VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
- for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
- const string& aFamilyName = aFamilyAndEntitySetIter->first;
- if(MYDEBUG) MESSAGE("ImportInfo - \t aFamilyName = '"<<aFamilyName<<"'");
- }
- }
- }
- //Reading information about fields
- med_int iFieldEnd = MEDnChamp(fid,0);
- if (iFieldEnd < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,0)");
- if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<<iFieldEnd);
- for(med_int iField = 1; iField <= iFieldEnd; iField++){
- med_int ncomp = MEDnChamp(fid,iField);
- if(ncomp < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,i)");
- valarray<char> aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1);
- valarray<char> aUnitNames('\0',ncomp*MED_TAILLE_PNOM + 1);
- char name_field[MED_TAILLE_NOM + 1] = "";
- med_type_champ type_field;
- if(MEDchampInfo(fid,iField,name_field,&type_field,&aCompNames[0],&aUnitNames[0],ncomp) < 0)
- throw std::runtime_error(string("ImportInfo >> MEDchampInfo(...)"));
- //if(type_field != MED_REEL64) continue; //There is some problem in reading INTXX values
- TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
- for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) {
- VISU::TEntity anEntity = aVisu2MedEntityIter->first;
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
- med_int iTimeStampEnd = MEDnPasdetemps(fid,name_field,aMedEntity,aGeom);
- if(iTimeStampEnd < 0) throw std::runtime_error("ImportInfo >> MEDnPasdetemps(...)");
- if(iTimeStampEnd > 0) {
- for(med_int iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++) {
- char aMeshName[MED_TAILLE_NOM+1] = "";
- med_int ngauss = 0, numdt = 0, numo = 0;
- char dt_unit[MED_TAILLE_PNOM+1] = "";
- med_float dt = 0;
- ret = MEDpasdetempsInfo(fid,name_field,aMedEntity,aGeom,iTimeStamp,
- aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...) < 0");
- if(myMeshMap.find(aMeshName) == myMeshMap.end())
- throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...)");
- VISU::TMesh &aMesh = myMeshMap[aMeshName];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- VISU::TFieldMap::iterator aFieldMapIter = aMeshOnEntity.myFieldMap.find(name_field);
- //if(MYDEBUG && aFieldMapIter == aMeshOnEntity.myFieldMap.end()){
- VISU::TField& aField = aMeshOnEntity.myFieldMap[name_field];
- if(iTimeStamp == 1){
- aField.myId = iField;
- aField.myName = name_field;
- aField.myEntity = anEntity;
- aField.myMeshName = aMeshName;
- aField.myNbComp = ncomp;
- aField.myNbValField = iTimeStampEnd;
- aField.myDataSize = aMeshOnEntity.myNbCells * ncomp;
- aField.myCompNames.resize(ncomp);
- aField.myUnitNames.resize(ncomp);
- if(MYDEBUG)
- MESSAGE("ImportInfo - aField.myName = '"<<name_field<<
- "'; myMeshName = '"<<aMeshName<<
- "'; myEntity = "<<anEntity<<
- "; myNbComp = "<<ncomp<<
- "; myDataSize = "<<aField.myDataSize);
- for(int iComp = 0, iPos = 0; iComp < ncomp; iComp++, iPos += MED_TAILLE_PNOM){
- char aCompName[MED_TAILLE_PNOM+1], aUnitName[MED_TAILLE_PNOM+1];
- strncpy(aCompName,&aCompNames[iPos],MED_TAILLE_PNOM);
- aCompName[MED_TAILLE_PNOM] = '\0';
- aField.myCompNames[iComp] = aCompName;
- strncpy(aUnitName,&aUnitNames[iPos],MED_TAILLE_PNOM);
- aUnitName[MED_TAILLE_PNOM] = '\0';
- aField.myUnitNames[iComp] = aUnitName;
- if(MYDEBUG)
- MESSAGE("ImportInfo - aCompName = '"<<aCompName<<"'; aUnitName = '"<<aUnitName<<"'");
- }
-
+
+ BEGMSG(MYDEBUG,"VISU::TGroup:\n");
+
+ VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
+ TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
+ for(;aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
+ const string& aGroupName = aGroupInfoIter->first;
+ const TFamilyGroup& aFamilyGroup = aGroupInfoIter->second;
+ PMEDGroup aGroup(new TMEDGroup());
+ aGroup->myName = aGroupName;
+ aGroup->myMeshName = aMesh->myName;
+
+ INITMSG(MYDEBUG,"aGroup->myName = '"<<aGroup->myName<<"'\n");
+
+ TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin();
+ for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){
+ const PFamilyInfo& aFamilyInfo = *aFamilyIter;
+ const string& aFamilyName = aFamilyInfo->GetName();
+
+ TEntity aVEntity = TEntity(-1);
+ PFamily aFamily;
+
+ // Find aVisuEntity
+ const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+ TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
+ for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
+ const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
+ const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+ TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
+ for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
+ const string& aName = aFamilyMapIter->first;
+ aFamily = aFamilyMapIter->second;
+ if(aName == aFamilyName){
+ aVEntity = aFamily->myEntity;
+ goto exit_lable;
}
- VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
- aValForTime.myId = iTimeStamp;
- aValForTime.myFieldName = aField.myName;
- aValForTime.myEntity = aField.myEntity;
- aValForTime.myMeshName = aField.myMeshName;
- aValForTime.myNbComp = aField.myNbComp;
- aValForTime.myTime = VISU::TField::TTime(dt,dt_unit);
- if(MYDEBUG && iGeomElem == 0)
- MESSAGE("ImportInfo -\t aValForTime.myTime = "<<dt<<", "<<dt_unit);
}
}
+ exit_lable:
+ if(aFamily && aVEntity >= 0){
+ aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity));
+ INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyName<<"'; '"<<aFamily->myName<<"'; aVEntity = "<<aVEntity<<"\n");
+
+ aGroup->myNbCells += aFamily->myNbCells;
+ aGroup->myCellsSize += aFamily->myCellsSize;
+ }
+ }
+ if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){
+ BEGMSG(MYDEBUG,"myNbCells = "<<aGroup->myNbCells<<
+ "; myCellsSize = "<<aGroup->myCellsSize<<"\n\n");
+ aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
}
}
+
+ TInt aNbFields = aMed->GetNbFields();
+ BEGMSG(MYDEBUG,"VISU::TField: NbFields="<<aNbFields<<"\n");
+ for(TInt iField = 1; iField <= aNbFields; iField++){
+ PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
+ TInt aNbComp = aFieldInfo->GetNbComp();
+ const string& aFieldName = aFieldInfo->GetName();
+
+ MED::TGeom aTGeom;
+ EEntiteMaillage aMEntity;
+ TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,aMEntity,aTGeom);
+ if (aNbTimeStamps<1)
+ continue;
+ TEntity aVEntity = MEDEntityToVTK(aMEntity);
+ VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
+ TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+ PMEDField aField = aFieldMap[aFieldName](new TMEDField());
+ aField->myId = iField;
+ aField->myNbComp = aNbComp;
+ aField->myEntity = aVEntity;
+ aField->myName = aFieldName;
+ aField->myMeshName = aMeshName;
+ aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
+ aField->myCompNames.resize(aNbComp);
+ aField->myUnitNames.resize(aNbComp);
+
+ INITMSG(MYDEBUG,"myName = '"<<aField->myName<<
+ "'; myId = "<<aField->myId<<
+ "; myEntity = "<<aField->myEntity<<
+ "; myDataSize = "<<aField->myDataSize<<
+ "; myNbComp = "<<aField->myNbComp<<"\n");
+
+ for(TInt iComp = 0; iComp < aNbComp; iComp++){
+ aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
+ aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
+ }
+
+ for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
+ PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo,
+ aMEntity,
+ aTGeom,
+ iTimeStamp);
+ TFloat aDt = aTimeStamp->GetDt();
+ const string& anUnitDt = aTimeStamp->GetUnitDt();
+ PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp);
+ TValField& aValField = aField->myValField;
+ PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
+ aValForTime->myId = iTimeStamp;
+ aValForTime->myFieldName = aField->myName;
+ aValForTime->myEntity = aField->myEntity;
+ aValForTime->myMeshName = aField->myMeshName;
+ aValForTime->myNbComp = aField->myNbComp;
+ aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
+ INITMSG(MYDEBUG,"aDt = "<<aDt<<", "<<anUnitDt<<"\n");
+ }
+ }
+ } catch (std::runtime_error& exc){
+ MSG(MYDEBUG,"Follow exception wqs occured in:\n"<<exc.what());
+ } catch(...){
+ EXCEPTION(runtime_error,"Unknown exception !!!");
}
+
return this;
}
-int VISU_MedConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
+int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity,
const string& theFamilyName)
- throw (std::runtime_error&)
{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- const string& aMeshName = theMeshOnEntity.myMeshName;
- const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
- VISU::TMesh& aMesh = myMeshMap[aMeshName];
+ PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
+ const string& aMeshName = theMeshOnEntity->myMeshName;
+ const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
+ PMeshImpl aMesh = myMeshMap[aMeshName];
int isPointsUpdated;
if(anEntity == VISU::NODE_ENTITY)
- isPointsUpdated = LoadPoints(fid,aMesh,theFamilyName);
- else
- isPointsUpdated = LoadPoints(fid,aMesh);
- int isCellsOnEntityUpdated = LoadCellsOnEntity(fid,theMeshOnEntity,theFamilyName);
+ isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName);
+ else
+ isPointsUpdated = LoadPoints(aMed,aMesh);
+ int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName);
return (isPointsUpdated || isCellsOnEntityUpdated);
}
-int VISU_MedConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh,
+int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh,
const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- throw (std::runtime_error&)
{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- int isPointsUpdated = 0;
- int isCellsOnEntityUpdated = 0;
+ PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
+ int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
const string& aFamilyName = aFamilyAndEntitySetIter->first;
const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
- VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
+ const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
if(anEntity == VISU::NODE_ENTITY){
- isPointsUpdated += LoadPoints(fid,theMesh,aFamilyName);
- isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity);
+ isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName);
+ isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity);
}else{
- isPointsUpdated += LoadPoints(fid,theMesh);
- isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity,aFamilyName);
+ isPointsUpdated += LoadPoints(aMed,theMesh);
+ isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName);
}
}
return (isPointsUpdated || isCellsOnEntityUpdated);
}
-int VISU_MedConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh,
- VISU::TMeshOnEntity& theMeshOnEntity,
- VISU::TField& theField,
- VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&)
+int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh,
+ VISU::PMeshOnEntityImpl theMeshOnEntity,
+ VISU::PFieldImpl theField,
+ VISU::PValForTimeImpl theValForTime)
{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- int isPointsUpdated = LoadPoints(fid,theMesh);
- int isCellsOnEntityUpdated = LoadCellsOnEntity(fid,theMeshOnEntity);
- int isFieldUpdated = LoadField(fid,theMeshOnEntity,theField,theValForTime);
+ PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
+ int isPointsUpdated = LoadPoints(aMed,theMesh);
+ int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
+ int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
}
-int VISU_MedConvertor::LoadPoints(const med_idt& fid, VISU::TMesh& theMesh, const string& theFamilyName)
- throw (std::runtime_error&)
+
+int
+VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed,
+ VISU::PMEDMesh theMesh,
+ const string& theFamilyName)
{
try{
//Check on existing family
- VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY];
- aMeshOnEntity.myEntity = VISU::NODE_ENTITY;
- aMeshOnEntity.myMeshName = theMesh.myName;
- VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- VISU::TFamily& aFamily = *pFamily;
+ VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
+ aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
+ aMeshOnEntity->myMeshName = theMesh->myName;
+ PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName);
//Check on loading already done
- bool isPointsLoaded = !theMesh.myPointsCoord.empty();
+ bool isPointsLoaded = !theMesh->myPointsCoord.empty();
if(isPointsLoaded)
- if(!isFamilyPresent) return 0;
- else if(!aFamily.mySubMesh.empty()) return 0;
- if(MYDEBUG)
- MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
+ if(!aFamily)
+ return 0;
+ else if(!aFamily->mySubMesh.empty())
+ return 0;
+
+ INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'\n");
+
//Main part of code
- char aMeshName[MED_TAILLE_NOM+1] = "";
- strcpy(aMeshName,theMesh.myName.c_str());
- med_geometrie_element typgeo = (med_geometrie_element)0; //MED_POINT1
- med_connectivite typco = (med_connectivite)0; //MED_NOD
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,typgeo,typco);
- if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> MEDnEntMaa(...)");
- if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
- med_repere rep;
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- valarray<char> name_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<char> unit_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<med_float> coord(theMesh.myDim*iNumElemEnd);
- ret = MEDnoeudsLire(fid,aMeshName,theMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
- &name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
- &num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("LoadPoints >> MEDnoeudsLire(...)");
+ PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
+ TInt aNbElem = aNodeInfo->GetNbElem();
+
if(!isPointsLoaded){
- VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
- aPointsCoord.resize(iNumElemEnd*theMesh.myDim);
- if(MYDEBUG) MESSAGE("LoadPoints - Filling coordinates of the mesh - inum_elem = "<<inum_elem);
- inum_elem = MED_FAUX; // It is workaround
- if(inum_elem == MED_FAUX)
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
- aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
- else
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
- aPointsCoord[num_elem[iNumElem2Dim]] = coord[iNumElem2Dim];
- if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
- VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
- aConnForCellType.resize(iNumElemEnd);
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem);
+ VISU::TMeshImpl::TPointsDim& aPointsDim = theMesh->myPointsDim;
+ aPointsDim.resize(theMesh->myDim);
+ for(int iDim = 0; iDim < theMesh->myDim; iDim++)
+ aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim);
+
+ VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
+ aPointsCoord.resize(aNbElem*theMesh->myDim);
+ for (int iElem = 0; iElem < aNbElem; iElem++)
+ for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++)
+ aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim);
+
+ VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
+ aConnForCellType.resize(aNbElem);
+ for (int iElem = 0; iElem < aNbElem; iElem++)
+ aConnForCellType[iElem] = VISU::TMeshOnEntityImpl::TConnect(1,iElem);
}
- if(isFamilyPresent && iNumElemEnd > 0){
- if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
- VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX];
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] == aFamily.myId)
- aSubMeshOnCellType.insert(iNumElem);
+ if(aFamily && aNbElem > 0){
+ VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
+ for (int iElem = 0; iElem < aNbElem; iElem++)
+ if(aNodeInfo->GetFamNum(iElem) == aFamily->myId)
+ aSubMeshOnCellType.insert(iElem);
}
return 1;
}catch(std::runtime_error& exc){
- theMesh.myPointsCoord.clear();
- throw std::runtime_error(exc.what());
+ theMesh->myPointsCoord.clear();
+ throw;
}catch(...){
- theMesh.myPointsCoord.clear();
- throw std::runtime_error("Unknown exception !!!");
+ theMesh->myPointsCoord.clear();
+ EXCEPTION(runtime_error,"Unknown exception !!!");
}
return 0;
}
-int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- throw (std::runtime_error&)
+
+int
+VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed,
+ VISU::PMEDMesh theMesh,
+ VISU::PMEDMeshOnEntity theMeshOnEntity,
+ const string& theFamilyName)
{
try{
//Check on existing family
- VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- VISU::TFamily& aFamily = *pFamily;
+ PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName);
//Check on loading already done
- bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty();
- if(isCellsLoaded)
- if(!isFamilyPresent) return 0;
- else if(!aFamily.mySubMesh.empty()) return 0;
- if(MYDEBUG) {
- MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
- MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<isFamilyPresent);
+ bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
+ if(isCellsLoaded)
+ if(!aFamily)
+ return 0;
+ else if(!aFamily->mySubMesh.empty())
+ return 0;
+
+ INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'\n");
+ BEGMSG(MYDEBUG,"LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily)<<endl);
+
+ const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
+ const EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
+
+ const PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
+ PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
+ TInt aNbPoints = aNodeInfo->GetNbElem();
+
+ std::map<TInt,TInt> aNodeIdMap;
+#ifdef _EDF_NODE_IDS_
+ EBooleen anIsNodeNum = eFAUX;
+#else
+ EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
+ if(anIsNodeNum){
+ for(TInt i = 0; i < aNbPoints; i++){
+ aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
+ }
}
- //Main part of code
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- const med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- char aMeshName[MED_TAILLE_NOM+1] = "";
- strcpy(aMeshName,theMeshOnEntity.myMeshName.c_str());
- if(MYDEBUG)
- MESSAGE("LoadCellsOnEntity - theMeshOnEntity.myEntity = "<<theMeshOnEntity.myEntity<<
- "; iGeomElemEnd = "<<iGeomElemEnd<<"; theFamilyName = '"<<theFamilyName<<"'");
- VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
- int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- int medId = getIdMedType(aGeomElemVector[iGeomElem]);
- int nbMedNodes = med2vtk[medId].medNbNodes;
- int nbVtkNodes = med2vtk[medId].vtkNbNodes;
- int aVtkType = med2vtk[medId].vtkType;
- med_geometrie_element aMedType = med2vtk[medId].medType;
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aMedType,MED_NOD);
- if (iNumElemEnd > 0) {
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim);
- if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<<med2vtk[medId].medName<<
- "; iNumElemEnd = "<<iNumElemEnd<<"; aNbConnForElem = "<<aNbConnForElem);
- valarray<med_int> conn(aNbConnForElem*iNumElemEnd);
- ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
- &name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
- &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("LoadCellsOnEntity >> MEDelementsLire(...)");
- if(!isCellsLoaded){
- VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
- aConnForCellType.resize(iNumElemEnd);
- valarray<med_int> aConnect(nbMedNodes);
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
- VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
- anArray.resize(nbVtkNodes);
- for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
- aConnect[k] = conn[kj+k] - 1;
- }
- switch(aMedType){
- case MED_TETRA4 :
- case MED_TETRA10 :
- anArray[0] = aConnect[0];
- anArray[1] = aConnect[1];
- anArray[2] = aConnect[3];
- anArray[3] = aConnect[2];
- break;
- case MED_PYRA5 :
- case MED_PYRA13 :
- anArray[0] = aConnect[0];
- anArray[1] = aConnect[3];
- anArray[2] = aConnect[2];
- anArray[3] = aConnect[1];
- anArray[4] = aConnect[4];
- break;
- default:
- for (int k = 0; k < nbVtkNodes; k++)
- anArray[k] = aConnect[k];
- }
- for (int k = 0; k < nbVtkNodes; k++)
- if(anArray[k] < 0 || aNbPoints <= anArray[k]){
- static QString aString;
- aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d](%d) < 0",aNbPoints,iNumElem,k,anArray[k]);
- throw std::runtime_error(aString.latin1());
+#endif
+
+ const MED::TGeom& aTGeom = theMeshOnEntity->myGeom;
+ MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+ TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn;
+
+ for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+ const EGeometrieElement& aGeom = anTGeomIter->first;
+ int aVTKGeomType = MEDGeomToVTK(aGeom);
+ ADDMSG(MYDEBUG,"LoadCellsOnEntity aGeom="<<aGeom<<"\n");
+ switch(aGeom){
+ case ePOLYGONE:
+ {
+ PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aPolygoneInfo->GetNbElem();
+
+ if(!isCellsLoaded){
+ VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType];
+ aConnForPolygoneType.resize(aNbElem);
+
+ int aMNbNodes = aPolygoneInfo->GetConnDim();
+
+ vector<TInt> aConnect(aMNbNodes);
+ vector<TInt> aIndex = aPolygoneInfo->GetIndex();
+
+ for (int iElem = 0; iElem < aNbElem; iElem++) {
+ VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem];
+ int aNbConn = aPolygoneInfo->GetNbConn(iElem);
+
+ anArray.resize(aNbConn);
+
+ aConnect = aPolygoneInfo->GetConnectivite();
+
+ for (int i=0;i<aNbConn;i++){
+ anArray[i] = aConnect[aIndex[iElem]-1+i]-1;
+ }
+ }
+ }
+ if(aFamily){
+ VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
+ for(int iElem = 0; iElem < aNbElem; iElem++)
+ if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId)
+ aSubMeshOnCellType.insert(iElem);
+ }
+ break;
+ }
+ case ePOLYEDRE:
+ {
+ PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aPolyedreInfo->GetNbElem();
+
+ int aMNbNodes = aPolyedreInfo->GetNbConn();
+ vector<TInt> aConnect(aMNbNodes);
+ aConnect = aPolyedreInfo->GetConnectivite();
+
+ if(!isCellsLoaded){
+ VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolyedreType = aCellsConn[aVTKGeomType];
+ aConnForPolyedreType.resize(aNbElem);
+
+ vector<TInt> aFacesIndex = aPolyedreInfo->GetFacesIndex();
+ vector<TInt> aIndex = aPolyedreInfo->GetIndex();
+
+ for (int iElem = 0; iElem < aNbElem; iElem++) {
+ set<TInt> aArrayNew;
+ VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolyedreType[iElem];
+
+ int aInd1 = aIndex[iElem]-1;
+ int aInd2 = aIndex[iElem+1]-2;
+
+ for (int i=aInd1;i<=aInd2;i++){
+ for (int j=aFacesIndex[i]-1;j<aFacesIndex[i+1]-1;j++){
+ aArrayNew.insert(aConnect[j]);
+ }
}
- }
- }
- //Filling aFamily SubMesh
- if(isFamilyPresent){
- VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType];
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] == aFamily.myId)
- aSubMeshOnCellType.insert(iNumElem);
- }
+
+ int aNbConnNew = aArrayNew.size();
+ anArray.resize(aNbConnNew);
+ set<TInt>::iterator aIter = aArrayNew.begin();
+ for (int i=0; aIter!=aArrayNew.end();aIter++, i++)
+ anArray[i] = (*aIter)-1;
+
+ }
+ }
+ if(aFamily){
+ VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
+ for(int iElem = 0; iElem < aNbElem; iElem++)
+ if(aPolyedreInfo->GetFamNum(iElem) == aFamily->myId)
+ aSubMeshOnCellType.insert(iElem);
+ }
+ break;
+ }
+ default:
+ {
+ int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType);
+
+ PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
+ TInt aNbElem = aCellInfo->GetNbElem();
+
+ if(!isCellsLoaded){
+ VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType];
+ aConnForCellType.resize(aNbElem);
+
+ int aMNbNodes = MEDGeom2NbNodes(aGeom);
+ vector<TInt> aConnect(aMNbNodes);
+
+ for (int iElem = 0; iElem < aNbElem; iElem++) {
+ VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem];
+ anArray.resize(aVNbNodes);
+
+ if(anIsNodeNum){
+ for(int i = 0; i < aMNbNodes; i++){
+ aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1];
+ }
+ }else{
+ for(int i = 0; i < aMNbNodes; i++){
+ aConnect[i] = aCellInfo->GetConn(iElem,i)-1;
+ }
+ }
+
+ switch(aGeom){
+ case eTETRA4:
+ case eTETRA10:
+ anArray[0] = aConnect[0];
+ anArray[1] = aConnect[1];
+ anArray[2] = aConnect[3];
+ anArray[3] = aConnect[2];
+ break;
+ case ePYRA5:
+ case ePYRA13:
+ anArray[0] = aConnect[0];
+ anArray[1] = aConnect[3];
+ anArray[2] = aConnect[2];
+ anArray[3] = aConnect[1];
+ anArray[4] = aConnect[4];
+ break;
+ default:
+ for(int iNode = 0; iNode < aVNbNodes; iNode++)
+ anArray[iNode] = aConnect[iNode];
+ }
+ for(int iNode = 0; iNode < aVNbNodes; iNode++)
+ if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
+ EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<<aNbPoints<<") "<<
+ "<= anArray["<<iElem<<"]"<<
+ "["<<iNode<<"]"<<
+ "("<<anArray[iNode]<<") < 0");
+ }
+ }
+ //Filling aFamily SubMesh
+ if(aFamily){
+ VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
+ for(int iElem = 0; iElem < aNbElem; iElem++)
+ if(aCellInfo->GetFamNum(iElem) == aFamily->myId)
+ aSubMeshOnCellType.insert(iElem);
+ }
+ }
}
}
return 1;
}catch(std::runtime_error& exc){
- theMeshOnEntity.myCellsConn.clear();
- throw std::runtime_error(exc.what());
+ theMeshOnEntity->myCellsConn.clear();
+ throw;
}catch(...){
- theMeshOnEntity.myCellsConn.clear();
- throw std::runtime_error("Unknown exception !!!");
+ theMeshOnEntity->myCellsConn.clear();
+ EXCEPTION(runtime_error,"Unknown exception !!!");
}
return 0;
}
-int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity,
- const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&)
+
+int
+VISU_MedConvertor::LoadField(const MED::PWrapper& theMed,
+ VISU::PMEDMesh theMesh,
+ VISU::PMEDMeshOnEntity theMeshOnEntity,
+ VISU::PMEDField theField,
+ VISU::PMEDValForTime theValForTime)
{
//Check on loading already done
- if(!theValForTime.myValForCells.empty()) return 0;
+ if(!theValForTime->myValForCells.empty()) return 0;
+
//Main part of code
- med_int ncomp = MEDnChamp(fid,theField.myId);
- if(ncomp < 0) throw std::runtime_error("LoadField >> MEDnChamp(fid,i)");
- valarray<char> comp('\0',ncomp*MED_TAILLE_PNOM + 1);
- valarray<char> unit('\0',ncomp*MED_TAILLE_PNOM + 1);
- char aFieldName[MED_TAILLE_NOM + 1] = "";
- med_type_champ type_field;
- if(MEDchampInfo(fid,theField.myId,aFieldName,&type_field,&comp[0],&unit[0],ncomp) < 0)
- throw std::runtime_error(string("LoadField >> MEDchampInfo(...)"));
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- const VISU::TEntity& anEntity = theField.myEntity;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- if(MYDEBUG) {
- MESSAGE("LoadField - aFieldName = '"<<aFieldName<<"'; anEntity = "<<anEntity<<"; iGeomElemEnd = "<<iGeomElemEnd);
- MESSAGE("LoadField - ncomp = "<<ncomp<<"; type_field = "<<type_field<<"; myId = "<<theValForTime.myId);
- }
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
- med_int iTimeStampEnd = MEDnPasdetemps(fid,aFieldName,aMedEntity,aGeom);
- if(iTimeStampEnd > 0) {
- char aMeshName[MED_TAILLE_NOM+1] = "";
- med_int ngauss = 0, numdt = 0, numo = 0;
- char dt_unit[MED_TAILLE_PNOM+1] = "";
- med_float dt = 0;
- ret = MEDpasdetempsInfo(fid,aFieldName,aMedEntity,aGeom,theValForTime.myId,
- aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("LoadField >> MEDpasdetempsInfo(...)");
- med_int nval = MEDnVal(fid,aFieldName,aMedEntity,aGeom,numdt,numo);
- if (nval <= 0) throw std::runtime_error("LoadField >> MEDnVal(...) - nval <= 0");
- else{
- //Checking for accordance between the mesh and the field on number of geomterical elements
- int aVtkType = med2vtkCellType(aGeom);
- const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
- if(aCellsConnIter == aCellsConn.end()) throw std::runtime_error("LoadField - There is no the geom. elem. on the mesh !!!");
- const VISU::TMeshOnEntity::TConnForCellType aConnForCellType = aCellsConnIter->second;
- if(aConnForCellType.size() != nval) throw std::runtime_error("LoadField - Size of values and size of mesh not equal !!!");
- if(MYDEBUG) MESSAGE("LoadField - aGeom = "<<aGeom<<"; nval = "<<nval<<"; iTimeStampEnd = "<<iTimeStampEnd);
- VISU::TField::TValForCellsWithType &anArray = theValForTime.myValForCells[aVtkType];
- int jEnd = theField.myNbComp*nval;
- anArray.resize(jEnd);
- char pflname[MED_TAILLE_NOM + 1] = "";
- switch(type_field){
- case MED_REEL64 : {
- valarray<med_float> valr(jEnd);
- ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
- pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
- break;
- }
- //case MED_INT64 : //valarray<long long> valr(jEnd);
- case MED_INT32 : //valarray<long int> valr(jEnd);
- case MED_INT : {
- valarray<med_int> valr(jEnd);
- ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
- pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
- break;
- }
- default :
- throw std::runtime_error("LoadField >> Value of med_type_champ for the field is wrong !!!");
+ const std::string& aMeshName = theMeshOnEntity->myMeshName;
+ const PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
+ PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,theField->myId);
+
+ MED::TGeom aTGeom;
+ EEntiteMaillage aMEntity;
+ theMed->GetNbTimeStamps(aFieldInfo,theMesh->myEntityInfo,aMEntity,aTGeom);
+
+ PTimeStampInfo aTimeStampInfo = theMed->GetPTimeStampInfo(aFieldInfo,
+ aMEntity,
+ aTGeom,
+ theValForTime->myId);
+ TInt aNbGauss = aTimeStampInfo->GetNbGauss();
+ TInt aNbComp = theField->myNbComp;
+
+ PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
+ bool anIsTrimmed = theField->myIsTrimmed;
+ INITMSG(MYDEBUG,"LoadField - aMeshName = '"<<aMeshName<<
+ "'; aFieldName = '"<<aFieldInfo->GetName()<<
+ "'; aMEntity = "<<aMEntity<<
+ "; anId = "<<theValForTime->myId<<endl);
+ BEGMSG(MYDEBUG,"LoadField - aNbComp = "<<aNbComp<<
+ "; aNbGauss = "<<aNbGauss<<endl);
+
+ const MED::TGeom& anEntityTGeom = theMeshOnEntity->myGeom;
+ MED::TGeom::const_iterator aTGeomIter = anEntityTGeom.begin();
+ for(; aTGeomIter != anEntityTGeom.end(); aTGeomIter++){
+ const EGeometrieElement& aGeom = aTGeomIter->first;
+ const TInt& aNbElem = aTGeomIter->second;
+
+ INITMSG(MYDEBUG,"LoadField - aGeom = "<<aGeom<<"; aNbElem = '"<<aNbElem<<endl);
+
+ if(aTGeom.find(aGeom) == aTGeom.end()){
+ if(!theField->myIsTrimmed){
+ theField->myDataSize -= aNbElem*theField->myNbComp;
+ anIsTrimmed = true;
+ }
+ }else{
+ int aVTKGeomType = MEDGeomToVTK(aGeom);
+ VISU::TValForTimeImpl::TValForCellsWithType& anArray = theValForTime->myValForCells[aVTKGeomType];
+ anArray.resize(aNbComp*aNbElem);
+ for(TInt iElem = 0, anId = 0; iElem < aNbElem; iElem++){
+ for(TInt iComp = 0; iComp < aNbComp; iComp++, anId++){
+ for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
+ anArray[anId] += aTimeStampVal->GetVal(aGeom,iElem,iComp,iGauss);
+ }
+ anArray[anId] /= aNbGauss;
}
- if(ret < 0) throw std::runtime_error("ChampLire >> MEDchampLire(...)");
}
}
}
+ theField->myIsTrimmed = anIsTrimmed;
return 1;
}