X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FCONVERTOR%2FVISU_MedConvertor.cxx;h=bc9e31d189302e56234b5228f9af575c97186180;hb=0ba0e8265a63906ca0c21ba420adc54aec0744b6;hp=9587f53f9c48aaf8517fe0c34b0ff291b3379ec9;hpb=17b175ff4b710fc93421509ffa7583edd1678a5d;p=modules%2Fvisu.git diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index 9587f53f..bc9e31d1 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -26,11 +26,20 @@ #include "VISU_MedConvertor.hxx" -#include +#include "VISU_Convertor.hxx" +#include "VISU_ConvertorUtils.hxx" + +#include "MED_Factory.hxx" +#include "MED_Algorithm.hxx" +#include "MED_Utilities.hxx" + #include -#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; @@ -38,674 +47,821 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif -static med_err ret = 0; -typedef map 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 = "<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 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 = "<> 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 = '"<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 = "<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 num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); - valarray 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 = "<> 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 = "<myNbCells<< + "; myCellsSize = "<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; iiGetNbConn(ii); + aMeshOnEntity->myCellsSize += aNbConnii; + } + INITMSG(MYDEBUG,"aGeom = "<GetFamNum(iElem); + if(aFamId != 0){ + aFamilyNbCellsCounterMap[aFamId] += 1; + ADDMSG(MYDEBUG,"aFamId="<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; iiGetNbConn(ii); + aMeshOnEntity->myCellsSize += aNbConnii; + } + INITMSG(MYDEBUG,"aGeom = "<GetFamNum(iElem); + std::string aName = aPolyedreInfo->GetElemName(iElem); + if(aFamId != 0){ + aFamilyNbCellsCounterMap[aFamId] += 1; + ADDMSG(MYDEBUG,"(aFamId="<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 = "<GetFamNum(iElem); + if(aFamId != 0){ + aFamilyNbCellsCounterMap[aFamId] += 1; + ADDMSG(MYDEBUG,"aFamId = "<> MEDfamInfo"); - if(0 && MYDEBUG) - MESSAGE("ImportInfo - aFamilyNum = "<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 = "<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 = "<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 = '"<myName<< + "'; myId = "<myId<<"; "<< + "; aNbAttr = "<GetNbAttr()<< + "; aNbGroup = "<GetNbGroup()<< + "; myEntity = "<myEntity<< + "; myNbCells = "<myNbCells<< + "; myCellsSize = "<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 = '"<> MEDnChamp(fid,0)"); - if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<> MEDnChamp(fid,i)"); - valarray aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1); - valarray 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 = '"<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 = '"<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 = "<= 0){ + aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity)); + INITMSG(MYDEBUG,"aFamilyName = '"<myName<<"'; aVEntity = "<myNbCells += aFamily->myNbCells; + aGroup->myCellsSize += aFamily->myCellsSize; + } + } + if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){ + BEGMSG(MYDEBUG,"myNbCells = "<myNbCells<< + "; myCellsSize = "<myCellsSize<<"\n\n"); + aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup)); } } + + TInt aNbFields = aMed->GetNbFields(); + BEGMSG(MYDEBUG,"VISU::TField: NbFields="<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 = '"<myName<< + "'; myId = "<myId<< + "; myEntity = "<myEntity<< + "; myDataSize = "<myDataSize<< + "; myNbComp = "<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 = "<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 = "<mySubMesh.empty()) + return 0; + + INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<> MEDnEntMaa(...)"); - if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "< num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); - valarray name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1); - valarray name_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1); - valarray unit_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1); - valarray 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 = "<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 = '"< 0) { - med_booleen iname_elem, inum_elem; - valarray num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); - valarray name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1); - med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim); - if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<> MEDelementsLire(...)"); - if(!isCellsLoaded){ - VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType]; - aConnForCellType.resize(iNumElemEnd); - valarray 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="<GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom); + TInt aNbElem = aPolygoneInfo->GetNbElem(); + + if(!isCellsLoaded){ + VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType]; + aConnForPolygoneType.resize(aNbElem); + + int aMNbNodes = aPolygoneInfo->GetConnDim(); + + vector aConnect(aMNbNodes); + vector 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;imySubMesh[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 aConnect(aMNbNodes); + aConnect = aPolyedreInfo->GetConnectivite(); + + if(!isCellsLoaded){ + VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolyedreType = aCellsConn[aVTKGeomType]; + aConnForPolyedreType.resize(aNbElem); + + vector aFacesIndex = aPolyedreInfo->GetFacesIndex(); + vector aIndex = aPolyedreInfo->GetIndex(); + + for (int iElem = 0; iElem < aNbElem; iElem++) { + set 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::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 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("<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 comp('\0',ncomp*MED_TAILLE_PNOM + 1); - valarray 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 = '"<> 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 = "< 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 valr(jEnd); - case MED_INT32 : //valarray valr(jEnd); - case MED_INT : { - valarray 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 = '"<