Back to index

salome-med  6.5.0
MEDMEMTest_DesactivateFacesComputation.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 
00022 #include "MEDMEM_Mesh.hxx"
00023 #include "MEDMEM_Group.hxx"
00024 #include "MEDMEM_Meshing.hxx"
00025 #include "MEDMEM_MedMeshDriver.hxx"
00026 #include "MEDMEM_GibiMeshDriver.hxx"
00027 
00028 #include <cppunit/Message.h>
00029 #include <cppunit/TestAssert.h>
00030 
00031 #ifdef WNT
00032 #include <windows.h>
00033 #endif
00034 
00035 using namespace std;
00036 using namespace MEDMEM;
00037 
00038 static void addMedFacesGroup2( MESHING& meshing, int nFaces, const int *groupValue,
00039                         string groupName, const MED_EN::medGeometryElement *mytypes,  const int *index, const int *myNumberOfElements, int nbOfGeomTypes)
00040   {
00041     GROUP *faces=new GROUP;
00042     faces->setName(groupName) ;
00043     faces->setMesh(&meshing) ;
00044     faces->setEntity(MED_EN::MED_FACE) ;
00045     faces->setNumberOfGeometricType(nbOfGeomTypes) ;
00046     faces->setGeometricType(mytypes);
00047     faces->setNumberOfElements(myNumberOfElements) ;
00048     faces->setNumber(index, groupValue) ;
00049     meshing.addGroup(*faces) ;
00050     faces->removeReference();
00051   }
00052 
00053 void MEDMEMTest::testDesactivateFacesComputation()
00054 {
00055   double coords[108]=
00056     {0, 0.21504, 0.21504, 0, 0.43008, 
00057      0.43008, 0.21504, 0, 0.43008, 0, 
00058      0.21504, 0.21504, 0, 0.43008, 
00059      0.43008, 0.21504, 0, 0.43008, 0, 
00060      0.21504, 0.21504, 0, 0.43008, 
00061      0.43008, 0.21504, 0, 0.43008, 0, 
00062      0.21504, 0.21504, 0, 0.43008, 
00063      0.43008, 0.21504, 0, 0.43008,
00064      //coordY
00065      0, 0, 0.21504, 0.21504, 0, 0.21504, 
00066      0.43008, 0.43008, 0.43008, 0, 0, 
00067      0.21504, 0.21504, 0, 0.21504, 
00068      0.43008, 0.43008, 0.43008, 0, 0, 
00069      0.21504, 0.21504, 0, 0.21504, 
00070      0.43008, 0.43008, 0.43008, 0, 0, 
00071      0.21504, 0.21504, 0, 0.21504, 
00072      0.43008, 0.43008, 0.43008,
00073      //coordZ
00074      0, 0, 0, 0, 0, 0, 0, 0, 0, 0.15677, 0.15677, 
00075      0.15677, 0.15677, 0.15677, 
00076      0.15677, 0.15677, 0.15677, 
00077      0.15677, 0.1934, 0.1934, 
00078      0.1934, 0.1934, 0.1934, 
00079      0.1934, 0.1934, 0.1934, 
00080      0.1934, 0.3485, 0.3485, 
00081      0.3485, 0.3485, 0.3485, 
00082      0.3485, 0.3485, 0.3485, 
00083      0.3485};
00084 
00085   int connNodalCellClassical[48]=
00086     { 1, 2, 3, 4, 10, 11, 12, 13, 
00087       4, 3, 7, 8, 13, 12, 16, 17, 
00088       10, 11, 12, 13, 19, 20, 21, 22, 
00089       13, 12, 16, 17, 22, 21, 25, 26, 
00090       19, 20, 21, 22, 28, 29, 30, 31,
00091       22, 21, 25, 26, 31, 30, 34, 35 };
00092 
00093   int connNodalFaceClassical[116]=
00094     { 1, 2, 3, 4, 
00095       10, 13, 12, 11, 
00096       1, 2, 11, 10, 
00097       2, 3, 12, 11, 
00098       3, 4, 13, 12, 
00099       4, 1, 10, 13, 
00100       4, 3, 7, 8, 
00101       13, 17, 16, 12, 
00102       3, 7, 16, 12, 
00103       7, 8, 17, 16, 
00104       8, 4, 13, 17, 
00105       19, 22, 21, 20, 
00106       10, 11, 20, 19,
00107       11, 12, 21, 20, 
00108       12, 13, 22, 21, 
00109       13, 10, 19, 22, 
00110       22, 26, 25, 21, 
00111       12, 16, 25, 21, 
00112       16, 17, 26, 25, 
00113       17, 13, 22, 26, 
00114       28, 31, 30, 29, 
00115       19, 20, 29, 28, 
00116       20, 21, 30, 29, 
00117       21, 22, 31, 30, 
00118       22, 19, 28, 31, 
00119       31, 35, 34, 30, 
00120       21, 25, 34, 30, 
00121       25, 26, 35, 34, 
00122       26, 22, 31, 35};
00123 
00124   int bottom[2]={1,7};
00125   MED_EN::medGeometryElement bottomTypes[1]={MED_EN::MED_QUAD4};
00126   int bottomIndex[2]={1,3};
00127   int bottomNbOfElts[1]={2};
00128   int top[4]={8,9,10,11};
00129   MED_EN::medGeometryElement topTypes[1]={MED_EN::MED_QUAD4};
00130   int topIndex[3]={1,5};
00131   int topNbOfElts[1]={4};
00132   int side[5]={ 3, 6, 10, 11, 13};
00133   MED_EN::medGeometryElement sideTypes[1]={MED_EN::MED_QUAD4};
00134   int sideIndex[2]={1,6};
00135   int sideNbOfElts[1]={5};
00136   //
00137   string tmp_dir=getTmpDirectory();
00138   string tmpfile=tmp_dir+"/toto3434535.med";
00139   string tmpGibiFile=tmp_dir+"/TET4.sauv";
00140   MEDMEMTest_TmpFilesRemover aRemover;
00141   aRemover.Register(tmpfile);
00142   aRemover.Register(tmpGibiFile);
00143   //
00144 
00145   MESHING* meshing = new MESHING;
00146   meshing->setName( "TESTMESH" );
00147   const int nNodes=36;
00148   meshing->setCoordinates(3, nNodes, coords, "CARTESIAN",
00149                           MED_EN::MED_NO_INTERLACE);
00150   string coordname[3] = { "x", "y", "z" };
00151   meshing->setCoordinatesNames(coordname);
00152   string coordunit[3] = { "m", "m", "m" };
00153   meshing->setCoordinatesUnits(coordunit);
00154   //Cell connectivity info for classical elts
00155   const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8};
00156   const int nbOfCellElts[1]={6};
00157   meshing->setNumberOfTypes(1,MED_EN::MED_CELL);
00158   meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL);
00159   meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL);
00160   //Face connectivity info for classical elts
00161   const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4};
00162   const int nbOfFaceElts[1]={14};
00163   meshing->setNumberOfTypes(1,MED_EN::MED_FACE);
00164   meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE);
00165   meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE);
00166   //All cell conn
00167   meshing->setConnectivity(MED_EN::MED_CELL,MED_EN::MED_HEXA8,connNodalCellClassical);
00168   //All face conn
00169   meshing->setConnectivity(MED_EN::MED_FACE,MED_EN::MED_QUAD4,connNodalFaceClassical);
00170   int nbOfTypes=meshing->getNumberOfTypes(MED_EN::MED_EDGE);
00171   addMedFacesGroup2( *meshing, 2,  bottom, "Bottom",bottomTypes,bottomIndex,bottomNbOfElts,1) ;
00172   addMedFacesGroup2( *meshing, 4,  top,    "TopFace",topTypes,topIndex,topNbOfElts,1) ;
00173   addMedFacesGroup2( *meshing, 5, side,   "SideFace",sideTypes,sideIndex,sideNbOfElts,1) ;
00174   //
00175   int id=meshing->addDriver(MED_DRIVER,tmpfile,meshing->getName());
00176   meshing->write(id);
00177   //
00178   MESH *mesh=new MESH;
00179   mesh->setName(meshing->getName());
00180   MEDMEM::MED_MESH_RDONLY_DRIVER *driver=new MEDMEM::MED_MESH_RDONLY_DRIVER(tmpfile,mesh);
00181   driver->desactivateFacesComputation();
00182   id=mesh->addDriver(*driver);
00183   mesh->read(id);
00184   CPPUNIT_ASSERT_NO_THROW(nbOfTypes=mesh->getNumberOfTypes(MED_EN::MED_EDGE));
00185   CPPUNIT_ASSERT_EQUAL(0,nbOfTypes);
00186   MEDMEM::GIBI_MESH_WRONLY_DRIVER *gibidriver=new MEDMEM::GIBI_MESH_WRONLY_DRIVER(tmpGibiFile,mesh );
00187   id=mesh->addDriver(*gibidriver);
00188   mesh->write(id);
00189 #ifdef WNT
00190   CPPUNIT_ASSERT( GetFileAttributes(tmpGibiFile.c_str()) != INVALID_FILE_ATTRIBUTES );
00191 #else
00192   CPPUNIT_ASSERT( access(tmpGibiFile.c_str(), F_OK) == 0 );
00193 #endif
00194 
00195   delete gibidriver;
00196   delete driver;
00197   //
00198   meshing->removeReference();
00199   mesh->removeReference();
00200 }