From f4613e1c365b2624ab610d7eab4deab7d6f5b623 Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 9 Aug 2005 09:38:22 +0000 Subject: [PATCH] To port on new version of MEDWrapper --- src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx | 714 +++++++++------------ src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 25 +- 2 files changed, 299 insertions(+), 440 deletions(-) diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index 1a0074604..e88e3598d 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -34,6 +34,7 @@ #include "SMESHDS_Group.hxx" #include "MED_Factory.hxx" +#include "MED_CoordUtils.hxx" #include "MED_Utilities.hxx" #include @@ -48,7 +49,9 @@ static int MYDEBUG = 0; using namespace MED; -void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName) +void +DriverMED_R_SMESHDS_Mesh +::SetMeshName(string theMeshName) { myMeshName = theMeshName; } @@ -61,83 +64,9 @@ FindNode(const SMDS_Mesh* theMesh, TInt theId){ } -enum ECoordName{eX, eY, eZ, eNone}; -typedef TFloat (*TGetCoord)(MED::PNodeInfo&, TInt); - -template -TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ - return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId); -} - -template<> -TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ - return 0.0; -} - - -static TGetCoord aXYZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -static TGetCoord aXYGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aYZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aXZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -static TGetCoord aXGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aYGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -class TCoordHelper{ - MED::PNodeInfo myPNodeInfo; - TGetCoord* myGetCoord; -public: - TCoordHelper(const MED::PNodeInfo& thePNodeInfo, - TGetCoord* theGetCoord): - myPNodeInfo(thePNodeInfo), - myGetCoord(theGetCoord) - {} - virtual ~TCoordHelper(){} - TFloat GetCoord(TInt theElemId, TInt theCoodId){ - return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId); - } -}; -typedef boost::shared_ptr TCoordHelperPtr; - - -Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() +Driver_Mesh::Status +DriverMED_R_SMESHDS_Mesh +::Perform() { Status aResult = DRS_FAIL; try{ @@ -192,49 +121,16 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() //------------------------------------------------------ PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); - TCoordHelperPtr aCoordHelperPtr; - { - TInt aMeshDimension = aMeshInfo->GetDim(); - bool anIsDimPresent[3] = {false, false, false}; - for(TInt iDim = 0; iDim < aMeshDimension; iDim++){ - string aDimName = aNodeInfo->GetCoordName(iDim); - if(aDimName == "x" || aDimName == "X") - anIsDimPresent[eX] = true; - else if(aDimName == "y" || aDimName == "Y") - anIsDimPresent[eY] = true; - else if(aDimName == "z" || aDimName == "Z") - anIsDimPresent[eZ] = true; - } - switch(aMeshDimension){ - case 3: - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord)); - break; - case 2: - if(anIsDimPresent[eY] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord)); - else if(anIsDimPresent[eX] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord)); - else - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord)); - break; - case 1: - if(anIsDimPresent[eY]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord)); - else if(anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord)); - else - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord)); - break; - } - } + PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo); EBooleen anIsNodeNum = aNodeInfo->IsElemNum(); TInt aNbElems = aNodeInfo->GetNbElem(); if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<GetPCellInfo(aMeshInfo,anEntity,aGeom); + EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX; + TInt aNbElems = aCellInfo->GetNbElem(); + if(MYDEBUG) MESSAGE("Perform - anEntity = "<GetFamNum(iElem); + try{ + //MESSAGE("Try to create element # " << iElem << " with id = " + // << aCellInfo->GetElemNum(iElem)); + switch(aGeom){ + case eSEG2: + case eSEG3: + if(anIsElemNum) + anElement = myMesh->AddEdgeWithID(aNodeIds[0], + aNodeIds[1], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1])); + isRenum = anIsElemNum; + } + break; + case eTRIA3: + case eTRIA6: + aNbNodes = 3; + if(anIsElemNum) + anElement = myMesh->AddFaceWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2])); + isRenum = anIsElemNum; + } + break; + case eQUAD4: + case eQUAD8: + aNbNodes = 4; + // There is some differnce between SMDS and MED + if(anIsElemNum) + anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1], aNodeIds[2], aNodeIds[3], - aNodeIds[4], - aNodeIds[5], - aNodeIds[6], - aNodeIds[7], aCellInfo->GetElemNum(iElem)); - if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + if (!anElement) { + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), FindNode(myMesh,aNodeIds[1]), FindNode(myMesh,aNodeIds[2]), - FindNode(myMesh,aNodeIds[3]), - FindNode(myMesh,aNodeIds[4]), - FindNode(myMesh,aNodeIds[5]), - FindNode(myMesh,aNodeIds[6]), - FindNode(myMesh,aNodeIds[7])); - isRenum = anIsElemNum; + FindNode(myMesh,aNodeIds[3])); + isRenum = anIsElemNum; + } + break; + case eTETRA4: + case eTETRA10: + aNbNodes = 4; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3])); + isRenum = anIsElemNum; + } + break; + case ePYRA5: + case ePYRA13: + aNbNodes = 5; + // There is some differnce between SMDS and MED + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4])); + isRenum = anIsElemNum; + } + break; + case ePENTA6: + case ePENTA15: + aNbNodes = 6; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5])); + isRenum = anIsElemNum; + } + break; + case eHEXA8: + case eHEXA20: + aNbNodes = 8; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], + aNodeIds[6], + aNodeIds[7], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5]), + FindNode(myMesh,aNodeIds[6]), + FindNode(myMesh,aNodeIds[7])); + isRenum = anIsElemNum; + } + break; } - break; + }catch(const std::exception& exc){ + //INFOS("Follow exception was cought:\n\t"<AddElement(anElement); - myFamilies[aFamNum]->SetType(anElement->GetType()); - } - } - } + if (!anElement) { + aResult = DRS_WARN_SKIP_ELEM; + } + else { + if (isRenum) { + anIsElemNum = eFAUX; + takeNumbers = false; + if (aResult < DRS_WARN_RENUMBER) + aResult = DRS_WARN_RENUMBER; + } + if (myFamilies.find(aFamNum) != myFamilies.end()) { + // Save reference to this element from its family + myFamilies[aFamNum]->AddElement(anElement); + myFamilies[aFamNum]->SetType(anElement->GetType()); + } + } + } + }} } } - break; } } }catch(const std::exception& exc){ diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 82e134adf..721bb5f07 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -365,8 +365,9 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() const ERepere SMDS_COORDINATE_SYSTEM = eCART; PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, - SMDS_COORDINATE_SYSTEM, aCoordinates, + eFULL_INTERLACE, + SMDS_COORDINATE_SYSTEM, aCoordNames, aCoordUnits, aFamilyNums, @@ -413,8 +414,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo, SMDS_MED_ENTITY, eSEG2, - SMDS_MED_CONNECTIVITY, aConnectivity, + SMDS_MED_CONNECTIVITY, aFamilyNums, anElemNums); myMed->SetCellInfo(aCellInfo); @@ -524,8 +525,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo, SMDS_MED_ENTITY, eTRIA3, - SMDS_MED_CONNECTIVITY, aTriaConn, + SMDS_MED_CONNECTIVITY, aTriaFamilyNums, anTriaElemNums); MESSAGE("Perform - anEntity = "<