Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEMBinTest / testAG.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_Mesh.hxx"
23 #include "MEDMEM_Group.hxx"
24 #include "MEDMEM_Meshing.hxx"
25 #include "MEDMEM_MedMeshDriver22.hxx"
26
27 using namespace MED_EN;
28 using namespace std;
29 using namespace MEDMEM;
30
31 void addMedFacesGroup( MESHING& meshing, int nFaces, int *groupValue,string groupName)
32   {
33     GROUP faces ;
34     int myNumberOfElements[1];
35     medGeometryElement mytypes[1];
36     int index[2];
37     int nbOfGeomTypes;
38     faces.setName(groupName) ;
39     faces.setMesh(&meshing) ;
40     faces.setEntity(MED_EN::MED_FACE) ;
41     faces.setNumberOfGeometricType(1) ;
42     mytypes[0]=MED_EN::MED_POLYGON;
43     faces.setGeometricType(mytypes);
44     myNumberOfElements[0]=nFaces;
45     faces.setNumberOfElements(myNumberOfElements) ;
46     index[0]=1; index[1]=nFaces;
47     faces.setNumber(index, groupValue) ;
48     meshing.addGroup(faces) ;
49   }
50
51 const int NB_OF_HEXA=1;
52 const int NB_OF_CELL_AXIAL=1;
53 char NomBottom[]="Bottom";
54
55 int main()
56 {
57   MESHING *pmesh=new MESHING;
58   pmesh->setName( "RJHMESH" ) ;
59   pmesh->setSpaceDimension(3) ;
60
61   double coord3DTab[36]={0.024155000000000003, 0.041837687256826218, -0.30499999999999999, 0.048310000000000013, -1.015761910347357e-17, -0.30499999999999999, 0.096620000000000011, -1.8329792978583059e-18,
62   -0.30499999999999999, 0.12077499999999999, 0.041837687256826225, -0.30499999999999999, 0.096620000000000011, 0.083675374513652451, -0.30499999999999999, 0.048310000000000013, 0.083675374513652465,
63   -0.30499999999999999, 0.024155000000000003, 0.041837687256826218, -0.2863, 0.048310000000000013, -1.015761910347357e-17, -0.2863, 0.096620000000000011, -1.8329792978583059e-18, -0.2863,
64   0.12077499999999999, 0.041837687256826225, -0.2863, 0.096620000000000011, 0.083675374513652451, -0.2863, 0.048310000000000013, 0.083675374513652465, -0.2863};
65   vector<double> coords3D(coord3DTab,coord3DTab+36);
66   unsigned nNodes=coords3D.size()/3;
67   pmesh->setNumberOfNodes(nNodes);
68   pmesh->setCoordinates(3, nNodes, &(coords3D[0]), "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
69   string coordname[3] = { "x", "y", "z" } ;
70   pmesh->setCoordinatesNames(coordname) ;
71   // Set coordinates units
72   string coordunit[3] = { "cm", "cm", "cm" } ;
73   pmesh->setCoordinatesUnits(coordunit) ;
74   pmesh->setNumberOfTypes(0, MED_EN::MED_CELL);
75   pmesh->setMeshDimension(3);
76   pmesh->setNumberOfTypes(1,MED_EN::MED_FACE);
77   medGeometryElement mytypes2D[1]={MED_QUAD4};
78   //
79   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};
80   vector<int> conn2DClassical(conn2DClassicalTab,conn2DClassicalTab+24);
81   //
82   int nbOfElemsFace=conn2DClassical.size()/4;
83   pmesh->setTypes(mytypes2D,MED_EN::MED_FACE);
84   pmesh->setNumberOfElements(&nbOfElemsFace,MED_EN::MED_FACE);
85   //
86   int polyHInd[2]={1, 9};
87   int polyHFaceInd[9]={1, 7, 13, 17, 21, 25, 29, 33, 37};
88   int polyHFaceConn[36]={8, 9, 10, 11, 12, 7, 2, 1, 6, 5, 4, 3, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 6, 12, 11, 6, 1, 7, 12, 1, 2, 8, 7};
89   //
90   pmesh->setPolyhedraConnectivity(polyHInd,polyHFaceInd,polyHFaceConn,NB_OF_HEXA*(NB_OF_CELL_AXIAL),MED_EN::MED_CELL);
91   pmesh->setConnectivity(&conn2DClassical[0], MED_EN::MED_FACE, MED_EN::MED_QUAD4);
92   //
93   int conn2DPolyIndTab[3]={1, 7, 13};
94   vector<int > conn2DPolyInd(conn2DPolyIndTab,conn2DPolyIndTab+3);
95   int conn2DPolyTab[12]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
96   //
97   pmesh->setPolygonsConnectivity(&conn2DPolyInd[0],conn2DPolyTab,conn2DPolyInd.size()-1,MED_EN::MED_FACE);
98   int bottom=7;
99   addMedFacesGroup(*pmesh,1,&bottom,NomBottom);
100   int id = pmesh->addDriver(MED_DRIVER, "coeur.med", pmesh->getName());
101   pmesh->write(id) ;
102         pmesh->rmDriver(id);
103   delete pmesh;
104   //
105   
106   MESH mesh;//(MED_DRIVER,,"RJHMESH");//"/home/geay/test_FGUI.med","FluidMesh_1");//../STEP3/coeur.med","RJHMESH");
107   mesh.setName("RJHMESH");
108   MED_MESH_RDONLY_DRIVER22 *drv=new MED_MESH_RDONLY_DRIVER22("coeur.med",&mesh);
109   drv->desactivateFacesComputation();
110   int newDrv=mesh.addDriver(*drv);
111   delete drv;
112   mesh.read(newDrv);
113   cout << " *** " << mesh.getNumberOfTypes(MED_EN::MED_FACE) << endl;
114   cout << "Expected 8 - having " << mesh.getNumberOfElementsWithPoly(MED_FACE,MED_ALL_ELEMENTS) << endl;
115   cout << "Expected 6 - having " << mesh.getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS) << endl;
116   cout << "Expected 6 - having " << mesh.getNumberOfElements(MED_FACE,MED_QUAD4) << endl;
117   cout << "Expected 1 - having " << mesh.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS) << endl;
118   cout << "Expected 0 - having " << mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) << endl;
119   return 0;
120 }