Back to index

salome-med  6.5.0
test_write_groups_poly.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 #include "MEDMEM_Meshing.hxx"
00023 #include "MEDMEM_Group.hxx"
00024 
00025 using namespace std;
00026 using namespace MEDMEM;
00027 using namespace MED_EN;
00028 
00029 static void addMedFacesGroup (MESHING& meshing, int nFaces, int *groupValue, string groupName)
00030 {
00031   GROUP *faces=new GROUP;
00032   int myNumberOfElements[1];
00033   medGeometryElement mytypes[1];
00034   int index[2];
00035   faces->setName(groupName);
00036   faces->setMesh(&meshing);
00037   faces->setEntity(MED_EN::MED_FACE);
00038   faces->setNumberOfGeometricType(1);
00039   mytypes[0] = MED_EN::MED_POLYGON;
00040   faces->setGeometricType(mytypes);
00041   myNumberOfElements[0] = nFaces;
00042   faces->setNumberOfElements(myNumberOfElements);
00043   index[0] = 1;
00044   index[1] = nFaces;
00045   faces->setNumber(index, groupValue);
00046   meshing.addGroup(*faces);
00047   faces->removeReference();
00048 }
00049 
00050 int main()
00051 {
00052   MESHING *pmesh = new MESHING;
00053   pmesh->setName( "C2MESH" );
00054   pmesh->setNumberOfTypes(0, MED_EN::MED_CELL);
00055   const int nb_hexagone = 7;
00056   const int nbmailles_axiales = 2;
00057   const int nb_polyH = nb_hexagone*(nbmailles_axiales-1);
00058   const int nb_polyG = nb_hexagone*nbmailles_axiales;
00059   const int nNodes = 6 * nb_hexagone * nbmailles_axiales;
00060 
00061  double coord[] = {
00062     44.401823743922364, 0                 , 0, 55.698259110886582, 6.5220000000000002, 0,
00063     55.698259110886582, 19.566000000000003, 0, 44.401823743922364, 26.088000000000001, 0,
00064     33.105388376958146, 19.566000000000003, 0, 33.105388376958146, 6.5220000000000002, 0,
00065     66.9946944778508  , 0                 , 0, 78.291129844815018, 6.5220000000000002, 0,
00066     78.291129844815018, 19.566000000000003, 0, 66.9946944778508  , 26.088000000000001, 0,
00067     55.698259110886582, 19.566000000000003, 0, 55.698259110886582, 6.5220000000000002, 0,
00068     33.105388376958146, 19.565999999999999, 0, 44.401823743922364, 26.088000000000001, 0,
00069     44.401823743922364, 39.131999999999998, 0, 33.105388376958146, 45.653999999999996, 0,
00070     21.808953009993928, 39.131999999999998, 0, 21.808953009993928, 26.088000000000001, 0,
00071     55.698259110886582, 19.565999999999999, 0, 66.9946944778508  , 26.088000000000001, 0,
00072     66.9946944778508  , 39.131999999999998, 0, 55.698259110886582, 45.653999999999996, 0,
00073     44.401823743922364, 39.131999999999998, 0, 44.401823743922364, 26.088000000000001, 0,
00074     78.291129844815018, 19.565999999999999, 0, 89.587565211779236, 26.088000000000001, 0,
00075     89.587565211779236, 39.131999999999998, 0, 78.291129844815018, 45.653999999999996, 0,
00076     66.9946944778508  , 39.131999999999998, 0, 66.9946944778508  , 26.088000000000001, 0,
00077     44.401823743922364, 39.132000000000005, 0, 55.698259110886582, 45.654000000000003, 0,
00078     55.698259110886582, 58.698            , 0, 44.401823743922364, 65.219999999999999, 0,
00079     33.105388376958146, 58.698            , 0, 33.105388376958146, 45.654000000000003, 0,
00080     66.9946944778508  , 39.132000000000005, 0, 78.291129844815018, 45.654000000000003, 0,
00081     78.291129844815018, 58.698            , 0, 66.9946944778508  , 65.219999999999999, 0,
00082     55.698259110886582, 58.698            , 0, 55.698259110886582, 45.654000000000003, 0,
00083     44.401823743922364, 0                 , 1, 55.698259110886582, 6.5220000000000002, 1,
00084     55.698259110886582, 19.566000000000003, 1, 44.401823743922364, 26.088000000000001, 1,
00085     33.105388376958146, 19.566000000000003, 1, 33.105388376958146, 6.5220000000000002, 1,
00086     66.9946944778508  , 0                 , 1, 78.291129844815018, 6.5220000000000002, 1,
00087     78.291129844815018, 19.566000000000003, 1, 66.9946944778508  , 26.088000000000001, 1,
00088     55.698259110886582, 19.566000000000003, 1, 55.698259110886582, 6.5220000000000002, 1,
00089     33.105388376958146, 19.565999999999999, 1, 44.401823743922364, 26.088000000000001, 1,
00090     44.401823743922364, 39.131999999999998, 1, 33.105388376958146, 45.653999999999996, 1,
00091     21.808953009993928, 39.131999999999998, 1, 21.808953009993928, 26.088000000000001, 1,
00092     55.698259110886582, 19.565999999999999, 1, 66.9946944778508  , 26.088000000000001, 1,
00093     66.9946944778508  , 39.131999999999998, 1, 55.698259110886582, 45.653999999999996, 1,
00094     44.401823743922364, 39.131999999999998, 1, 44.401823743922364, 26.088000000000001, 1,
00095     78.291129844815018, 19.565999999999999, 1, 89.587565211779236, 26.088000000000001, 1,
00096     89.587565211779236, 39.131999999999998, 1, 78.291129844815018, 45.653999999999996, 1,
00097     66.9946944778508  , 39.131999999999998, 1, 66.9946944778508  , 26.088000000000001, 1,
00098     44.401823743922364, 39.132000000000005, 1, 55.698259110886582, 45.654000000000003, 1,
00099     55.698259110886582, 58.698            , 1, 44.401823743922364, 65.219999999999999, 1,
00100     33.105388376958146, 58.698            , 1, 33.105388376958146, 45.654000000000003, 1,
00101     66.9946944778508  , 39.132000000000005, 1, 78.291129844815018, 45.654000000000003, 1,
00102     78.291129844815018, 58.698            , 1, 66.9946944778508  , 65.219999999999999, 1,
00103     55.698259110886582, 58.698            , 1, 55.698259110886582, 45.654000000000003, 1};
00104 
00105   pmesh->setCoordinates(3, nNodes, coord, "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
00106 
00107   string coordname[3] = { "x", "y", "z" };
00108   pmesh->setCoordinatesNames(coordname);
00109 
00110   // Set coordinates units
00111   string coordunit[3] = { "cm", "cm", "cm" };
00112   pmesh->setCoordinatesUnits(coordunit);
00113 
00114   const medGeometryElement types[] = { MED_EN::MED_POLYGON, MED_EN::MED_POLYHEDRA };
00115   
00116   pmesh->setNumberOfTypes(1, MED_EN::MED_CELL);
00117   pmesh->setTypes( & types[1], MED_EN::MED_CELL );
00118   pmesh->setNumberOfElements( & nb_polyH, MED_CELL );
00119 
00120   pmesh->setNumberOfTypes(1, MED_EN::MED_FACE);
00121   pmesh->setTypes( & types[0], MED_EN::MED_FACE );
00122   pmesh->setNumberOfElements( & nb_polyG, MED_FACE );
00123 
00124   int polyHInd[nb_polyH+1] = {1, 44, 87, 130, 173, 216, 259, 302 };
00125   int polyHConn[301] = {
00126     1,2,3,4,5,6,      -1, 43,44,45,46,47,48,-1, 1,2,44,43,  -1, 2,3,45,44,  -1,
00127     3,4,46,45,        -1, 4,5,47,46,        -1, 5,6,48,47,  -1, 6,1,43,48,       // #1
00128     7,8,9,10,3,2,     -1, 49,50,51,52,45,44,-1, 7,8,50,49,  -1, 8,9,51,50,  -1,
00129     9,10,52,51,       -1, 10,3,45,52,       -1, 3,2,44,45,  -1, 2,7,49,44,       // #2
00130     5,4,15,16,17,18,  -1, 47,46,57,58,59,60,-1, 5,4,46,47,  -1, 4,15,57,46, -1,
00131     15,16,58,57,      -1, 16,17,59,58,      -1, 17,18,60,59,-1, 18,5,47,60,      // #3
00132     3,10,21,22,15,4,  -1, 45,52,63,64,57,46,-1, 3,10,52,45, -1, 10,21,63,52,-1,
00133     21,22,64,63,      -1, 22,15,57,64,      -1, 15,4,46,57, -1, 4,3,45,46,       // #4
00134     9,26,27,28,21,10, -1, 51,68,69,70,63,52,-1, 9,26,68,51, -1, 26,27,69,68,-1,
00135     27,28,70,69,      -1, 28,21,63,70,      -1, 21,10,52,63,-1, 10,9,51,52,      // #5
00136     15,22,33,34,35,16,-1, 57,64,75,76,77,58,-1, 15,22,64,57,-1, 22,33,75,64,-1,
00137     33,34,76,75,      -1, 34,35,77,76,      -1, 35,16,58,77,-1, 16,15,57,58,     // #6
00138     21,28,39,40,33,22,-1, 63,70,81,82,75,64,-1, 21,28,70,63,-1, 28,39,81,70,-1,
00139     39,40,82,81,      -1, 40,33,75,82,      -1, 33,22,64,75,-1, 22,21,63,64};    // #7
00140 
00141   pmesh->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA, polyHConn, polyHInd);
00142 
00143   int cpolygonsindex[nb_polyG+1] = {1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85};
00144   int connec[] = {
00145     1 , 2 , 3 , 4 , 5 , 6 ,
00146     7 , 8 , 9 , 10, 3 , 2 ,
00147     5 , 4 , 15, 16, 17, 18,
00148     3 , 10, 21, 22, 15, 4 ,
00149     9 , 26, 27, 28, 21, 10,
00150     15, 22, 33, 34, 35, 16,
00151     21, 28, 39, 40, 33, 22,
00152     43, 44, 45, 46, 47, 48,
00153     49, 50, 51, 52, 45, 44,
00154     47, 46, 57, 58, 59, 60,
00155     45, 52, 63, 64, 57, 46,
00156     51, 68, 69, 70, 63, 52,
00157     57, 64, 75, 76, 77, 58,
00158     63, 70, 81, 82, 75, 64};
00159 
00160   pmesh->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_POLYGON,connec, cpolygonsindex);
00161 
00162   int bottom[] = {1, 2, 3, 4, 5, 6, 7};
00163   addMedFacesGroup(*pmesh, nb_hexagone, bottom, "BottomFaces");
00164 
00165   int id = pmesh->addDriver(MED_DRIVER, "cronoshexa.med", pmesh->getName());
00166   pmesh->write(id);
00167   pmesh->removeReference();
00168 
00169   if ( getenv("srcdir") )
00170     /* we are in 'make check' */
00171     remove( "cronoshexa.med" );
00172 
00173   return 0;
00174 }