Back to index

salome-med  6.5.0
test_MEDMEM_MeshingPoly.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_Meshing.hxx"
00024 #include "MEDMEM_Field.hxx"
00025 
00026 using namespace std;
00027 using namespace MEDMEM;
00028 using namespace MED_EN;
00029 
00030 int main (int argc, char ** argv) 
00031 {
00032   double Coordinates[57] = 
00033     {
00034       2.0, 3.0, 2.0,
00035       3.0, 2.0, 2.0,
00036       4.0, 1.0, 2.0,
00037       2.0, 0.0, 2.0,
00038       0.0, 1.0, 2.0,
00039       1.0, 2.0, 2.0,
00040       2.0, 3.0, 1.0,
00041       3.0, 2.0, 0.0,
00042       4.0, 1.0, 0.0,
00043       2.0, 0.0, 0.0,
00044       0.0, 1.0, 0.0,
00045       1.0, 2.0, 0.0,
00046       5.0, 3.0, 2.0,
00047       7.0, 2.0, 2.0,
00048       6.0, 0.0, 2.0,
00049       6.0, 3.0, 0.0,
00050       7.0, 2.0, 0.0,
00051       6.0, 0.0, -1.0,
00052       5.0, 1.0, -3.0
00053     };
00054 
00055   const int REFnodalConnOfFaces[91] = 
00056     {
00057       1, 2, 3, 4, 5, 6, -1,// Polyhedron 1
00058       1, 7, 8, 2,       -1,
00059       2, 8, 9, 3,       -1,
00060       4, 3, 9, 10,      -1,
00061       5, 4, 10, 11,     -1,
00062       6, 5, 11, 12,     -1,
00063       1, 6, 12, 7,      -1,
00064       7, 12, 8,         -1,
00065       10, 9, 8, 12, 11,
00066 
00067       13, 14, 15, 3, 2, -1, // Polyhedron 2
00068       13, 2, 8, 16,     -1,
00069       14, 13, 16, 17,   -1,
00070       15, 14, 17,       -1,
00071       15, 17, 18,       -1,
00072       15, 18, 9,        -1,
00073       3, 15, 9,         -1,
00074       2, 3, 9, 8,       -1,
00075       8, 9, 17, 16,     -1,
00076       9, 18, 17
00077     };
00078 
00079   const int REFpolyIndex[3] = 
00080     {
00081       1, 47, 92 
00082     };
00083 
00084   double PolygonCoordinates[27] = 
00085     {
00086       2.0, 3.0, 12.0,
00087       3.0, 2.0, 12.0,
00088       4.0, 1.0, 12.0,
00089       2.0, 0.0, 12.0,
00090       0.0, 1.0, 12.0,
00091       1.0, 2.0, 12.0,
00092       5.0, 3.0, 12.0,
00093       7.0, 2.0, 12.0,
00094       6.0, 0.0, 12.0
00095     };
00096 
00097   const int REFpolygonFaces[11] = 
00098     {
00099       1, 2, 3, 4, 5, 6, // Polygon 1   
00100       7, 8, 9, 3, 2     // Polygon 2
00101     }; 
00102 
00103   const int REFpolygonIndex[3] =
00104     {
00105       1, 7, 12
00106     };
00107 
00108   MESHING *myMeshing=new MESHING;
00109   myMeshing->setName("meshing");
00110 
00111   int NumberOfNodes = 19;
00112   int SpaceDimension = 3;
00113 
00114   const int NumberOfTypes = 2;
00115   medGeometryElement Types[NumberOfTypes] = 
00116     {
00117       MED_TETRA4, MED_POLYHEDRA
00118     };
00119   const int NumberOfElements[NumberOfTypes] = 
00120     {
00121       1,2
00122     };
00123 
00124   myMeshing->setNumberOfTypes(NumberOfTypes, MED_CELL);
00125 
00126   myMeshing->setCoordinates(SpaceDimension, NumberOfNodes, Coordinates,
00127                             "CARTESIAN", MED_FULL_INTERLACE);
00128   myMeshing->setTypes(Types, MED_CELL);
00129   myMeshing->setNumberOfElements(NumberOfElements, MED_CELL);
00130 
00131   string Names[3] =
00132     {
00133       "X","Y","Z"
00134     };
00135   myMeshing->setCoordinatesNames(Names);
00136 
00137   string Units[3] =
00138     {
00139       "cm","cm","cm"
00140     };
00141   myMeshing->setCoordinatesUnits(Units);
00142 
00143   const int sizeTetra = 4*1 ;
00144   int ConnectivityTetra[sizeTetra]=
00145     {
00146       17, 9, 18, 19
00147     };
00148 
00149   myMeshing->setConnectivity(MED_CELL, MED_TETRA4, ConnectivityTetra);
00150 
00151   myMeshing->setConnectivity(MED_CELL, MED_POLYHEDRA, REFnodalConnOfFaces, REFpolyIndex);
00152 
00153 
00154   MESHING *myPolygonMeshing=new MESHING;
00155   myPolygonMeshing->setName("PolygonMeshing");
00156 
00157   NumberOfNodes = 9;
00158   SpaceDimension = 3;
00159   medGeometryElement PolygonTypes[NumberOfTypes] = 
00160     {
00161       MED_TRIA3,MED_POLYGON
00162     };
00163   const int PolygonNumberOfElements[NumberOfTypes] = 
00164     {
00165       2,2
00166     };
00167 
00168   myPolygonMeshing->setNumberOfTypes(NumberOfTypes, MED_CELL);
00169 
00170   myPolygonMeshing->setCoordinates(SpaceDimension, NumberOfNodes, PolygonCoordinates,
00171                                    "CARTESIAN", MED_FULL_INTERLACE);
00172   myPolygonMeshing->setTypes(PolygonTypes, MED_CELL);
00173   myPolygonMeshing->setNumberOfElements(PolygonNumberOfElements, MED_CELL);
00174 
00175   myPolygonMeshing->setCoordinatesNames(Names);
00176   myPolygonMeshing->setCoordinatesUnits(Units);
00177 
00178   const int sizeTri = 3*2 ;
00179   int ConnectivityTri[sizeTri]=
00180     {
00181       1, 7, 2, 3, 9, 4
00182     };
00183 
00184   myPolygonMeshing->setConnectivity(MED_CELL, MED_TRIA3,   ConnectivityTri);
00185   myPolygonMeshing->setConnectivity(MED_CELL, MED_POLYGON, REFpolygonFaces, REFpolygonIndex);
00186   FIELD<double> *areas = myPolygonMeshing->getArea(myPolygonMeshing->getSupportOnAll( MED_CELL ));
00187   myPolygonMeshing->removeReference();
00188   const double *vals2 = areas->getValue();
00189   const double REFAreaOfPolyg[4] =
00190     {
00191       1.5, 2, 6, 6.5
00192     };
00193   int nbPts=0;
00194   int i;
00195   for(i=0;i<4;i++)
00196     if(fabs(REFAreaOfPolyg[i]-vals2[i])<1e-12)
00197       nbPts++;
00198   areas->removeReference();
00199 
00200   const SUPPORT *sup = myMeshing->getSupportOnAll(MED_CELL);
00201   FIELD<double> *vols = myMeshing->getVolume(sup,false);
00202   const double *vals = vols->getValue();
00203   const double REFVolOfPolyHedron[3] =
00204     {
00205       2.333333333333333, -11.66666666666666, -13.83224131414673
00206     };
00207   for(i=0;i<3;i++)
00208     if(fabs(REFVolOfPolyHedron[i]-vals[i])<1e-12)
00209       nbPts++;
00210 
00211   vols->removeReference();
00212   if(nbPts==7)
00213     {
00214       cout << "ALL TESTS OK !!!" << endl;
00215     }
00216   else
00217     {
00218       cout << "TEST FAILS !!!" << endl;
00219       return -1;
00220     }
00221   cout << "Writing test " << endl;
00222   myMeshing->write(MED_DRIVER,"totoPoly_V22.med");
00223   myMeshing->removeReference();
00224   if ( getenv("srcdir") ) // performing 'make check'?
00225     remove("totoPoly_V22.med");
00226   return 0;
00227 }