Back to index

salome-med  6.5.0
testAG.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 "MEDMEM_Mesh.hxx"
00024 #include "MEDMEM_Group.hxx"
00025 #include "MEDMEM_Meshing.hxx"
00026 #include "MEDMEM_MedMeshDriver22.hxx"
00027 
00028 using namespace MED_EN;
00029 using namespace std;
00030 using namespace MEDMEM;
00031 
00032 void addMedFacesGroup( MESHING& meshing, int nFaces, int *groupValue,string groupName)
00033   {
00034     GROUP faces ;
00035     int myNumberOfElements[1];
00036     medGeometryElement mytypes[1];
00037     int index[2];
00038     int nbOfGeomTypes;
00039     faces.setName(groupName) ;
00040     faces.setMesh(&meshing) ;
00041     faces.setEntity(MED_EN::MED_FACE) ;
00042     faces.setNumberOfGeometricType(1) ;
00043     mytypes[0]=MED_EN::MED_POLYGON;
00044     faces.setGeometricType(mytypes);
00045     myNumberOfElements[0]=nFaces;
00046     faces.setNumberOfElements(myNumberOfElements) ;
00047     index[0]=1; index[1]=nFaces;
00048     faces.setNumber(index, groupValue) ;
00049     meshing.addGroup(faces) ;
00050   }
00051 
00052 const int NB_OF_HEXA=1;
00053 const int NB_OF_CELL_AXIAL=1;
00054 char NomBottom[]="Bottom";
00055 
00056 int main()
00057 {
00058   MESHING *pmesh=new MESHING;
00059   pmesh->setName( "RJHMESH" ) ;
00060 
00061   double coord3DTab[36]={0.024155000000000003, 0.041837687256826218, -0.30499999999999999, 0.048310000000000013, -1.015761910347357e-17, -0.30499999999999999, 0.096620000000000011, -1.8329792978583059e-18,
00062   -0.30499999999999999, 0.12077499999999999, 0.041837687256826225, -0.30499999999999999, 0.096620000000000011, 0.083675374513652451, -0.30499999999999999, 0.048310000000000013, 0.083675374513652465,
00063   -0.30499999999999999, 0.024155000000000003, 0.041837687256826218, -0.2863, 0.048310000000000013, -1.015761910347357e-17, -0.2863, 0.096620000000000011, -1.8329792978583059e-18, -0.2863,
00064   0.12077499999999999, 0.041837687256826225, -0.2863, 0.096620000000000011, 0.083675374513652451, -0.2863, 0.048310000000000013, 0.083675374513652465, -0.2863};
00065   vector<double> coords3D(coord3DTab,coord3DTab+36);
00066   unsigned nNodes=coords3D.size()/3;
00067   pmesh->setCoordinates(3, nNodes, &(coords3D[0]), "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00068   string coordname[3] = { "x", "y", "z" } ;
00069   pmesh->setCoordinatesNames(coordname) ;
00070   // Set coordinates units
00071   string coordunit[3] = { "cm", "cm", "cm" } ;
00072   pmesh->setCoordinatesUnits(coordunit) ;
00073 
00074   medGeometryElement mytypes3D[1]={MED_POLYHEDRA};
00075   medGeometryElement mytypes2D[2]={MED_QUAD4,MED_POLYGON};
00076   pmesh->setNumberOfTypes(1, MED_EN::MED_CELL);
00077   pmesh->setNumberOfTypes(2,MED_EN::MED_FACE);
00078   pmesh->setTypes(mytypes3D,MED_EN::MED_CELL);
00079   pmesh->setTypes(mytypes2D,MED_EN::MED_FACE);
00080   //
00081   const int nbPolyH = 1;
00082   int polyHInd[2]={1, 9};
00083   int polyHFaceConn[43]={8, 9, 10, 11, 12, 7, -1,
00084                          2, 1, 6,  5,  4,  3, -1,
00085                          2, 3, 9,  8,         -1,
00086                          3, 4, 10, 9,         -1,
00087                          4, 5, 11, 10,        -1,
00088                          5, 6, 12, 11,        -1,
00089                          6, 1, 7, 12,         -1,
00090                          1, 2, 8, 7};
00091   //
00092   int conn2DClassicalTab[24]={2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 6, 12, 11, 6, 1, 7, 12, 1, 2, 8, 7};
00093   vector<int> conn2DClassical(conn2DClassicalTab,conn2DClassicalTab+24);
00094   //
00095   int conn2DPolyIndTab[3]={1, 7, 13};
00096   vector<int > conn2DPolyInd(conn2DPolyIndTab,conn2DPolyIndTab+3);
00097   int conn2DPolyTab[12]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
00098   //
00099   int nbOfElemsFace[] = { conn2DClassical.size()/4, conn2DPolyInd.size()-1 };
00100   pmesh->setNumberOfElements(&nbPolyH,MED_EN::MED_CELL);
00101   pmesh->setNumberOfElements(nbOfElemsFace,MED_EN::MED_FACE);
00102   //
00103   //
00104   pmesh->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA, polyHFaceConn,polyHInd);
00105   pmesh->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_QUAD4,&conn2DClassical[0]);
00106   pmesh->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_POLYGON,&conn2DPolyInd[0],conn2DPolyIndTab);
00107   int bottom=7;
00108   addMedFacesGroup(*pmesh,1,&bottom,NomBottom);
00109   int id = pmesh->addDriver(MED_DRIVER, "coeur.med", pmesh->getName());
00110   pmesh->write(id) ;
00111   pmesh->rmDriver(id);
00112   delete pmesh;
00113   //
00114   
00115   MESH mesh;//(MED_DRIVER,,"RJHMESH");//"/home/geay/test_FGUI.med","FluidMesh_1");//../STEP3/coeur.med","RJHMESH");
00116   mesh.setName("RJHMESH");
00117   MED_MESH_RDONLY_DRIVER22 *drv=new MED_MESH_RDONLY_DRIVER22("coeur.med",&mesh);
00118   drv->desactivateFacesComputation();
00119   int newDrv=mesh.addDriver(*drv);
00120   delete drv;
00121   mesh.read(newDrv);
00122   cout << " *** " << mesh.getNumberOfTypes(MED_EN::MED_FACE) << endl;
00123   cout << "Expected 8 - having " << mesh.getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS) << endl;
00124   cout << "Expected 6 - having " << mesh.getNumberOfElements(MED_FACE,MED_QUAD4) << endl;
00125   cout << "Expected 1 - having " << mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) << endl;
00126   return 0;
00127 }