Version: 6.3.1

src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "DriverUNV_R_SMDS_Mesh.h"
00024 #include "SMDS_Mesh.hxx"
00025 #include "SMDS_MeshGroup.hxx"
00026 
00027 #include "utilities.h"
00028 
00029 #include "UNV2411_Structure.hxx"
00030 #include "UNV2412_Structure.hxx"
00031 #include "UNV2417_Structure.hxx"
00032 #include "UNV_Utilities.hxx"
00033 
00034 #include <Basics_Utils.hxx>
00035 
00036 using namespace std;
00037 
00038 
00039 #ifdef _DEBUG_
00040 static int MYDEBUG = 1;
00041 #else
00042 static int MYDEBUG = 0;
00043 #endif
00044 
00045 
00046 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
00047 {
00048   if (myGroup != 0) 
00049     delete myGroup;
00050 }
00051 
00052 
00053 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
00054 {
00055   Kernel_Utils::Localizer loc;
00056   Status aResult = DRS_OK;
00057   std::ifstream in_stream(myFile.c_str());
00058   try{
00059     {
00060       using namespace UNV2411;
00061       TDataSet aDataSet2411;
00062       UNV2411::Read(in_stream,aDataSet2411);
00063       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
00064       TDataSet::const_iterator anIter = aDataSet2411.begin();
00065       for(; anIter != aDataSet2411.end(); anIter++){
00066         const TNodeLab& aLabel = anIter->first;
00067         const TRecord& aRec = anIter->second;
00068         //MESSAGE("AddNodeWithID " << aLabel << " " << aRec.coord[0] << " " << aRec.coord[1] << " " << aRec.coord[2]);
00069         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
00070       }
00071     }
00072     {
00073       using namespace UNV2412;
00074       in_stream.seekg(0);
00075       TDataSet aDataSet2412;
00076       UNV2412::Read(in_stream,aDataSet2412);
00077       TDataSet::const_iterator anIter = aDataSet2412.begin();
00078       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00079       for(; anIter != aDataSet2412.end(); anIter++){
00080         SMDS_MeshElement* anElement = NULL;
00081         const TElementLab& aLabel = anIter->first;
00082         const TRecord& aRec = anIter->second;
00083         if(IsBeam(aRec.fe_descriptor_id)) {
00084           switch ( aRec.node_labels.size() ) {
00085           case 2: // edge with two nodes
00086             //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1]);
00087             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
00088                                               aRec.node_labels[1],
00089                                               aLabel);
00090             break;
00091           case 3: // quadratic edge (with 3 nodes)
00092             //MESSAGE("add edge " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2]);
00093             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
00094                                               aRec.node_labels[2],
00095                                               aRec.node_labels[1],
00096                                               aLabel);
00097           }
00098         }
00099         else if(IsFace(aRec.fe_descriptor_id)) {
00100           //MESSAGE("add face " << aLabel);
00101           switch(aRec.fe_descriptor_id){
00102           case 41: // Plane Stress Linear Triangle      
00103           case 51: // Plane Strain Linear Triangle      
00104           case 61: // Plate Linear Triangle             
00105           case 74: // Membrane Linear Triangle          
00106           case 81: // Axisymetric Solid Linear Triangle 
00107           case 91: // Thin Shell Linear Triangle        
00108             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
00109                                               aRec.node_labels[1],
00110                                               aRec.node_labels[2],
00111                                               aLabel);
00112             break;
00113             
00114           case 42: //  Plane Stress Parabolic Triangle       
00115           case 52: //  Plane Strain Parabolic Triangle       
00116           case 62: //  Plate Parabolic Triangle              
00117           case 72: //  Membrane Parabolic Triangle           
00118           case 82: //  Axisymetric Solid Parabolic Triangle  
00119           case 92: //  Thin Shell Parabolic Triangle         
00120             //MESSAGE("add face " << aLabel << " " << aRec.node_labels[0] << " " << aRec.node_labels[1] << " " << aRec.node_labels[2] << " " << aRec.node_labels[3] << " " << aRec.node_labels[4] << " " << aRec.node_labels[5]);
00121             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
00122                                               aRec.node_labels[2],
00123                                               aRec.node_labels[4],
00124                                               aRec.node_labels[1],
00125                                               aRec.node_labels[3],
00126                                               aRec.node_labels[5],
00127                                               aLabel);
00128             break;
00129             
00130           case 44: // Plane Stress Linear Quadrilateral     
00131           case 54: // Plane Strain Linear Quadrilateral     
00132           case 64: // Plate Linear Quadrilateral            
00133           case 71: // Membrane Linear Quadrilateral         
00134           case 84: // Axisymetric Solid Linear Quadrilateral
00135           case 94: // Thin Shell Linear Quadrilateral       
00136             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
00137                                               aRec.node_labels[1],
00138                                               aRec.node_labels[2],
00139                                               aRec.node_labels[3],
00140                                               aLabel);
00141             break;
00142             
00143           case 45: // Plane Stress Parabolic Quadrilateral      
00144           case 55: // Plane Strain Parabolic Quadrilateral      
00145           case 65: // Plate Parabolic Quadrilateral             
00146           case 75: // Membrane Parabolic Quadrilateral          
00147           case 85: // Axisymetric Solid Parabolic Quadrilateral 
00148           case 95: // Thin Shell Parabolic Quadrilateral        
00149             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
00150                                               aRec.node_labels[2],
00151                                               aRec.node_labels[4],
00152                                               aRec.node_labels[6],
00153                                               aRec.node_labels[1],
00154                                               aRec.node_labels[3],
00155                                               aRec.node_labels[5],
00156                                               aRec.node_labels[7],
00157                                               aLabel);
00158             break;
00159           }
00160         }
00161         else if(IsVolume(aRec.fe_descriptor_id)){
00162           //MESSAGE("add volume " << aLabel);
00163           switch(aRec.fe_descriptor_id){
00164             
00165           case 111: // Solid Linear Tetrahedron - TET4
00166             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00167                                                 aRec.node_labels[2],
00168                                                 aRec.node_labels[1],
00169                                                 aRec.node_labels[3],
00170                                                 aLabel);
00171             break;
00172 
00173           case 118: // Solid Quadratic Tetrahedron - TET10
00174             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00175                                                 aRec.node_labels[4],
00176                                                 aRec.node_labels[2],
00177 
00178                                                 aRec.node_labels[9],
00179 
00180                                                 aRec.node_labels[5],
00181                                                 aRec.node_labels[3],
00182                                                 aRec.node_labels[1],
00183 
00184                                                 aRec.node_labels[6],
00185                                                 aRec.node_labels[8],
00186                                                 aRec.node_labels[7],
00187                                                 aLabel);
00188             break;
00189             
00190           case 112: // Solid Linear Prism - PRISM6
00191             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00192                                                 aRec.node_labels[2],
00193                                                 aRec.node_labels[1],
00194                                                 aRec.node_labels[3],
00195                                                 aRec.node_labels[5],
00196                                                 aRec.node_labels[4],
00197                                                 aLabel);
00198             break;
00199             
00200           case 113: // Solid Quadratic Prism - PRISM15
00201             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00202                                                 aRec.node_labels[4],
00203                                                 aRec.node_labels[2],
00204 
00205                                                 aRec.node_labels[9],
00206                                                 aRec.node_labels[13],
00207                                                 aRec.node_labels[11],
00208 
00209                                                 aRec.node_labels[5],
00210                                                 aRec.node_labels[3],
00211                                                 aRec.node_labels[1],
00212 
00213                                                 aRec.node_labels[14],
00214                                                 aRec.node_labels[12],
00215                                                 aRec.node_labels[10],
00216 
00217                                                 aRec.node_labels[6],
00218                                                 aRec.node_labels[8],
00219                                                 aRec.node_labels[7],
00220                                                 aLabel);
00221             break;
00222             
00223           case 115: // Solid Linear Brick - HEX8
00224             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00225                                                 aRec.node_labels[3],
00226                                                 aRec.node_labels[2],
00227                                                 aRec.node_labels[1],
00228                                                 aRec.node_labels[4],
00229                                                 aRec.node_labels[7],
00230                                                 aRec.node_labels[6],
00231                                                 aRec.node_labels[5],
00232                                                 aLabel);
00233             break;
00234 
00235           case 116: // Solid Quadratic Brick - HEX20
00236             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00237                                                 aRec.node_labels[6],
00238                                                 aRec.node_labels[4],
00239                                                 aRec.node_labels[2],
00240 
00241                                                 aRec.node_labels[12],
00242                                                 aRec.node_labels[18],
00243                                                 aRec.node_labels[16],
00244                                                 aRec.node_labels[14],
00245 
00246                                                 aRec.node_labels[7],
00247                                                 aRec.node_labels[5],
00248                                                 aRec.node_labels[3],
00249                                                 aRec.node_labels[1],
00250 
00251                                                 aRec.node_labels[19],
00252                                                 aRec.node_labels[17],
00253                                                 aRec.node_labels[15],
00254                                                 aRec.node_labels[13],
00255 
00256                                                 aRec.node_labels[8],
00257                                                 aRec.node_labels[11],
00258                                                 aRec.node_labels[10],
00259                                                 aRec.node_labels[9],
00260                                                 aLabel);
00261             break;
00262 
00263           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
00264             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
00265                                                 aRec.node_labels[6],
00266                                                 aRec.node_labels[4],
00267                                                 aRec.node_labels[2],
00268                                                 aRec.node_labels[7],
00269                                                 aRec.node_labels[5],
00270                                                 aRec.node_labels[3],
00271                                                 aRec.node_labels[1],
00272 
00273                                                 aRec.node_labels[8],
00274                                                 aRec.node_labels[11],
00275                                                 aRec.node_labels[10],
00276                                                 aRec.node_labels[9],
00277                                                 aRec.node_labels[12],
00278                                                 aLabel);
00279             break;
00280 
00281           }
00282         }
00283         if(!anElement)
00284           MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
00285       }
00286     }
00287     {
00288       using namespace UNV2417;      
00289       in_stream.seekg(0);
00290       TDataSet aDataSet2417;
00291       UNV2417::Read(in_stream,aDataSet2417);
00292       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
00293       if  (aDataSet2417.size() > 0) {
00294         myGroup = new SMDS_MeshGroup(myMesh);
00295         TDataSet::const_iterator anIter = aDataSet2417.begin();
00296         for(; anIter != aDataSet2417.end(); anIter++){
00297           const TGroupId& aLabel = anIter->first;
00298           const TRecord& aRec = anIter->second;
00299 
00300           int aNodesNb = aRec.NodeList.size();
00301           int aElementsNb = aRec.ElementList.size();
00302 
00303           bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
00304           int i;
00305           if (aNodesNb > 0) {
00306             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
00307             std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
00308             int i = aGrName.find( "\r" );
00309             if (i > 0)
00310               aGrName.erase (i, 2);
00311             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
00312             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
00313 
00314             for (i = 0; i < aNodesNb; i++) {
00315               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
00316               if (aNode)
00317                 aNodesGroup->Add(aNode);
00318             }
00319           }
00320           if (aElementsNb > 0){
00321             SMDS_MeshGroup* aEdgesGroup = 0;
00322             SMDS_MeshGroup* aFacesGroup = 0;
00323             SMDS_MeshGroup* aVolumeGroup = 0;
00324             bool createdGroup = false;
00325 
00326             for (i = 0; i < aElementsNb; i++) {
00327               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
00328               if (aElement) {
00329                 switch (aElement->GetType()) {
00330                 case SMDSAbs_Edge:
00331                   if (!aEdgesGroup) {
00332                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
00333                     if (!useSuffix && createdGroup) useSuffix = true;
00334                     std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
00335                     int i = aEdgesGrName.find( "\r" );
00336                     if (i > 0)
00337                       aEdgesGrName.erase (i, 2);
00338                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
00339                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
00340                     createdGroup = true;
00341                   }
00342                   aEdgesGroup->Add(aElement);
00343                   break;
00344                 case SMDSAbs_Face:
00345                   if (!aFacesGroup) {
00346                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
00347                     if (!useSuffix && createdGroup) useSuffix = true;
00348                     std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
00349                     int i = aFacesGrName.find( "\r" );
00350                     if (i > 0)
00351                       aFacesGrName.erase (i, 2);
00352                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
00353                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
00354                     createdGroup = true;
00355                   }
00356                   aFacesGroup->Add(aElement);
00357                   break;
00358                 case SMDSAbs_Volume:
00359                   if (!aVolumeGroup) {
00360                     aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
00361                     if (!useSuffix && createdGroup) useSuffix = true;
00362                     std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
00363                     int i = aVolumeGrName.find( "\r" );
00364                     if (i > 0)
00365                       aVolumeGrName.erase (i, 2);
00366                     myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
00367                     myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
00368                     createdGroup = true;
00369                   }
00370                   aVolumeGroup->Add(aElement);
00371                   break;
00372                 }
00373               } 
00374             }
00375           }
00376         }
00377       }
00378     } 
00379   }
00380   catch(const std::exception& exc){
00381     INFOS("Follow exception was cought:\n\t"<<exc.what());
00382   }
00383   catch(...){
00384     INFOS("Unknown exception was cought !!!");
00385   }
00386   if (myMesh)
00387     myMesh->compactMesh();
00388   return aResult;
00389 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS