Back to index

salome-smesh  6.5.0
DriverDAT_R_SMDS_Mesh.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 <stdio.h>
00024 
00025 #include "DriverDAT_R_SMDS_Mesh.h"
00026 #include "SMDS_Mesh.hxx"
00027 
00028 #include "utilities.h"
00029 
00030 #include <Basics_Utils.hxx>
00031 
00032 using namespace std;
00033 
00034 Driver_Mesh::Status DriverDAT_R_SMDS_Mesh::Perform()
00035 {
00036   Kernel_Utils::Localizer loc;
00037   Status aResult = DRS_OK;
00038 
00039   int i, j;
00040   int nbNodes, nbCells;
00041   int intNumPoint;
00042   float coordX, coordY, coordZ;
00043   int nbNoeuds;
00044   
00045   int intNumMaille, Degre;
00046   int ValElement;
00047   int NoeudsMaille[20];
00048   int NoeudMaille;
00049   
00050   MESSAGE("in DriverDAT_R_SMDS_Mesh::Read()");
00051   /****************************************************************************
00052    *                      OUVERTURE DU FICHIER EN LECTURE                      *
00053    ****************************************************************************/
00054   char *file2Read = (char *)myFile.c_str();
00055   FILE* aFileId = fopen(file2Read, "r");
00056   if (aFileId < 0) {
00057     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
00058     return DRS_FAIL;
00059   }
00060   
00061   fscanf(aFileId, "%d %d\n", &nbNodes, &nbCells);
00062   
00063   /****************************************************************************
00064    *                       LECTURE DES NOEUDS                                  *
00065    ****************************************************************************/
00066   fprintf(stdout, "\n(************************)\n");
00067   fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
00068   fprintf(stdout, "(************************)\n");
00069   
00070   for (i = 0; i < nbNodes; i++){
00071     fscanf(aFileId, "%d %e %e %e\n", &intNumPoint, &coordX, &coordY, &coordZ);
00072     myMesh->AddNodeWithID(coordX, coordY, coordZ, intNumPoint);
00073   }
00074   
00075   fprintf(stdout, "%d noeuds\n", myMesh->NbNodes());
00076   /****************************************************************************
00077    *                       LECTURE DES ELEMENTS                                *
00078    ****************************************************************************/
00079   fprintf(stdout, "\n(**************************)\n");
00080   fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
00081   fprintf(stdout, "(**************************)");
00082   
00083   fprintf(stdout, "%d elements\n", nbCells);
00084   
00085   for (i = 0; i < nbCells; i++) {
00086     fscanf(aFileId, "%d %d", &intNumMaille, &ValElement);
00087     Degre = abs(ValElement / 100);
00088     nbNoeuds = ValElement - (Degre * 100);
00089     
00090     // Recuperation des noeuds de la maille
00091     for (j = 0; j < nbNoeuds; j++) {
00092       fscanf(aFileId, "%d", &NoeudMaille);
00093       NoeudsMaille[j] = NoeudMaille;
00094     }
00095     
00096     // Analyse des cas de cellules
00097     switch (ValElement) {
00098     case 102:
00099     case 103:
00100       nbNoeuds = 2;
00101       myMesh->AddEdgeWithID(NoeudsMaille[0], NoeudsMaille[1], 
00102                                  intNumMaille);
00103       break;
00104     case 204:
00105     case 208:
00106       nbNoeuds = 4;
00107       myMesh->AddFaceWithID(NoeudsMaille[0], NoeudsMaille[1],
00108                                  NoeudsMaille[2], NoeudsMaille[3], 
00109                                  intNumMaille);
00110       break;
00111     case 203:
00112     case 206:
00113       nbNoeuds = 3;
00114       myMesh->AddFaceWithID(NoeudsMaille[0], NoeudsMaille[1],
00115                                  NoeudsMaille[2], intNumMaille);
00116       break;
00117     case 308:
00118     case 320:
00119       nbNoeuds = 8;
00120       if (ValElement == 320){
00121         //A voir, correspondance VTK
00122         NoeudsMaille[4] = NoeudsMaille[8];
00123         NoeudsMaille[5] = NoeudsMaille[9];
00124         NoeudsMaille[6] = NoeudsMaille[10];
00125         NoeudsMaille[7] = NoeudsMaille[11];
00126       }
00127       myMesh->AddVolumeWithID(NoeudsMaille[0], NoeudsMaille[1],
00128                                    NoeudsMaille[2], NoeudsMaille[3], 
00129                                    NoeudsMaille[4], NoeudsMaille[5], 
00130                                    NoeudsMaille[6], NoeudsMaille[7],
00131                                    intNumMaille);
00132       break;
00133     case 304:
00134     case 310:
00135       nbNoeuds = 4;
00136       if (ValElement == 310)
00137         NoeudsMaille[3] = NoeudsMaille[6];
00138       myMesh->AddVolumeWithID(NoeudsMaille[0], NoeudsMaille[1],
00139                                    NoeudsMaille[2], NoeudsMaille[3], 
00140                                    intNumMaille);
00141       break;
00142     case 306:
00143     case 315:
00144       nbNoeuds = 8;
00145       if (ValElement == 315) {
00146         NoeudsMaille[3] = NoeudsMaille[6];
00147         NoeudsMaille[4] = NoeudsMaille[7];
00148         NoeudsMaille[5] = NoeudsMaille[8];
00149       }
00150       NoeudsMaille[7] = NoeudsMaille[5];
00151       NoeudsMaille[6] = NoeudsMaille[5];
00152       NoeudsMaille[5] = NoeudsMaille[4];
00153       NoeudsMaille[4] = NoeudsMaille[3];
00154       NoeudsMaille[3] = NoeudsMaille[2];
00155       myMesh->AddVolumeWithID(NoeudsMaille[0], NoeudsMaille[1],
00156                                    NoeudsMaille[2], NoeudsMaille[3], 
00157                                    NoeudsMaille[4], NoeudsMaille[5], 
00158                                    intNumMaille);
00159                                 break;
00160     }
00161   }
00162   /****************************************************************************
00163    *                      FERMETURE DU FICHIER                      *
00164    ****************************************************************************/
00165   fclose(aFileId);
00166   return aResult;
00167 }