Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEMBinTest / testAG.cxx
1 // Copyright (C) 2007-2013  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
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEM_Group.hxx"
25 #include "MEDMEM_Meshing.hxx"
26 #include "MEDMEM_MedMeshDriver22.hxx"
27
28 using namespace MED_EN;
29 using namespace std;
30 using namespace MEDMEM;
31
32 void addMedFacesGroup( MESHING& meshing, int nFaces, int *groupValue,string groupName)
33   {
34     GROUP faces ;
35     int myNumberOfElements[1];
36     medGeometryElement mytypes[1];
37     int index[2];
38     int nbOfGeomTypes;
39     faces.setName(groupName) ;
40     faces.setMesh(&meshing) ;
41     faces.setEntity(MED_EN::MED_FACE) ;
42     faces.setNumberOfGeometricType(1) ;
43     mytypes[0]=MED_EN::MED_POLYGON;
44     faces.setGeometricType(mytypes);
45     myNumberOfElements[0]=nFaces;
46     faces.setNumberOfElements(myNumberOfElements) ;
47     index[0]=1; index[1]=nFaces;
48     faces.setNumber(index, groupValue) ;
49     meshing.addGroup(faces) ;
50   }
51
52 const int NB_OF_HEXA=1;
53 const int NB_OF_CELL_AXIAL=1;
54 char NomBottom[]="Bottom";
55
56 int main()
57 {
58   MESHING *pmesh=new MESHING;
59   pmesh->setName( "RJHMESH" ) ;
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->setCoordinates(3, nNodes, &(coords3D[0]), "CARTESIAN",MED_EN::MED_FULL_INTERLACE);
68   string coordname[3] = { "x", "y", "z" } ;
69   pmesh->setCoordinatesNames(coordname) ;
70   // Set coordinates units
71   string coordunit[3] = { "cm", "cm", "cm" } ;
72   pmesh->setCoordinatesUnits(coordunit) ;
73
74   medGeometryElement mytypes3D[1]={MED_POLYHEDRA};
75   medGeometryElement mytypes2D[2]={MED_QUAD4,MED_POLYGON};
76   pmesh->setNumberOfTypes(1, MED_EN::MED_CELL);
77   pmesh->setNumberOfTypes(2,MED_EN::MED_FACE);
78   pmesh->setTypes(mytypes3D,MED_EN::MED_CELL);
79   pmesh->setTypes(mytypes2D,MED_EN::MED_FACE);
80   //
81   const int nbPolyH = 1;
82   int polyHInd[2]={1, 9};
83   int polyHFaceConn[43]={8, 9, 10, 11, 12, 7, -1,
84                          2, 1, 6,  5,  4,  3, -1,
85                          2, 3, 9,  8,         -1,
86                          3, 4, 10, 9,         -1,
87                          4, 5, 11, 10,        -1,
88                          5, 6, 12, 11,        -1,
89                          6, 1, 7, 12,         -1,
90                          1, 2, 8, 7};
91   //
92   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};
93   vector<int> conn2DClassical(conn2DClassicalTab,conn2DClassicalTab+24);
94   //
95   int conn2DPolyIndTab[3]={1, 7, 13};
96   vector<int > conn2DPolyInd(conn2DPolyIndTab,conn2DPolyIndTab+3);
97   int conn2DPolyTab[12]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
98   //
99   int nbOfElemsFace[] = { conn2DClassical.size()/4, conn2DPolyInd.size()-1 };
100   pmesh->setNumberOfElements(&nbPolyH,MED_EN::MED_CELL);
101   pmesh->setNumberOfElements(nbOfElemsFace,MED_EN::MED_FACE);
102   //
103   //
104   pmesh->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA, polyHFaceConn,polyHInd);
105   pmesh->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_QUAD4,&conn2DClassical[0]);
106   pmesh->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_POLYGON,&conn2DPolyInd[0],conn2DPolyIndTab);
107   int bottom=7;
108   addMedFacesGroup(*pmesh,1,&bottom,NomBottom);
109   int id = pmesh->addDriver(MED_DRIVER, "coeur.med", pmesh->getName());
110   pmesh->write(id) ;
111   pmesh->rmDriver(id);
112   delete pmesh;
113   //
114   
115   MESH mesh;//(MED_DRIVER,,"RJHMESH");//"/home/geay/test_FGUI.med","FluidMesh_1");//../STEP3/coeur.med","RJHMESH");
116   mesh.setName("RJHMESH");
117   MED_MESH_RDONLY_DRIVER22 *drv=new MED_MESH_RDONLY_DRIVER22("coeur.med",&mesh);
118   drv->desactivateFacesComputation();
119   int newDrv=mesh.addDriver(*drv);
120   delete drv;
121   mesh.read(newDrv);
122   cout << " *** " << mesh.getNumberOfTypes(MED_EN::MED_FACE) << endl;
123   cout << "Expected 8 - having " << mesh.getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS) << endl;
124   cout << "Expected 6 - having " << mesh.getNumberOfElements(MED_FACE,MED_QUAD4) << endl;
125   cout << "Expected 1 - having " << mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) << endl;
126   return 0;
127 }