Back to index

salome-med  6.5.0
create_poly3D.c
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 /*
00024   creation d'une geometrie 3d : 
00025   maillé en :
00026   - 2 polyedres
00027     ayant pour faces 3 polygones
00028                      9 quadrangles
00029                      6 triangles
00030   - 1 tetra4
00031 
00032 */
00033 
00034 #include <med.h>
00035 #include <string.h>
00036 #include <stdlib.h>
00037 
00038 int main (int argc, char **argv)
00039 {
00040   med_err ret;
00041   med_idt fid;
00042   char maa[MED_NAME_SIZE+1] = "poly3D";
00043   char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 3D avec 2 polyedres+1tetra4 comme mailles et 3 polygones comme faces";
00044   med_int mdim = 3;
00045   med_int nnoe = 19;
00046   /*
00047     les noeuds:
00048   */
00049   med_float coo[57] = {
00050     2.0, 3.0, 2.0,
00051     3.0, 2.0, 2.0,
00052     4.0, 1.0, 2.0,
00053     2.0, 0.0, 2.0,
00054     0.0, 1.0, 2.0,
00055     1.0, 2.0, 2.0,
00056     2.0, 3.0, 1.0,
00057     3.0, 2.0, 0.0,
00058     4.0, 1.0, 0.0,
00059     2.0, 0.0, 0.0,
00060     0.0, 1.0, 0.0,
00061     1.0, 2.0, 0.0,
00062     5.0, 3.0, 2.0,
00063     7.0, 2.0, 2.0,
00064     6.0, 0.0, 2.0,
00065     6.0, 3.0, 0.0,
00066     7.0, 2.0, 0.0,
00067     6.0, 0.0, -1.0,
00068     5.0, 1.0, -3.0 
00069   };
00070   char nomcoo[3*MED_SNAME_SIZE+1] = "x               y               z               ";
00071   char unicoo[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
00072   /*  char nomnoe[18*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
00073   //char *nomnoe ;
00074 //  med_int numnoe[19] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
00075   med_int nufano[19] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
00076   /*
00077     les elements:
00078   */
00079   /* Faces QUAD4 */
00080   med_int nquad4 = 8;
00081   med_int quad4[32] = {
00082     1, 7, 8, 2,
00083     2, 8, 9, 3,
00084     4, 3, 9, 10,
00085     5, 4, 10, 11,
00086     6, 5, 11, 12,
00087     1, 6, 12, 7,
00088     14, 13, 16, 17,
00089     8, 9, 17, 16
00090   };
00091  // char nomquad4[MED_TAILLE_PNOM*8+1] = "quad1           quad2           quad3           quad4           quad5           quad6           quad7           quad8           ";
00092  // med_int numquad4[9] = {2,3,4,5,6,7,12,17};
00093   med_int nufaquad4[9] = {-1,-1,-1,-1,-1,-1,-1,-1};
00094 
00095   /* Faces TRIA3 */
00096   med_int ntria3 = 6;
00097   med_int tria3[18] = {
00098     7, 12, 8,
00099     15, 14, 17,
00100     15, 17, 18,
00101     15, 18, 9,
00102     3, 15, 9,
00103     18, 17, 9
00104   };
00105  // char nomtria3[MED_TAILLE_PNOM*6+1] = "tria1           tria2           tria3           tria4           tria5           tria6           ";
00106  // med_int numtria3[6] = {8,13,14,15,16,18};
00107   med_int nufatria3[6] = {-2,-2,-2,-2,-2,-2};
00108 
00109   /* Faces POLYGONE */
00110   med_int npolygon = 3;
00111   med_int nindexpolygon = 4;
00112   med_int indexpolygon [4] = {
00113     1, 7, 12, 17
00114   };
00115   med_int polygon[16] = {
00116     1, 2, 3, 4, 5, 6,
00117     10, 9, 8, 12, 11,
00118     13, 14, 15, 3, 2
00119   };
00120   //char nompolygon[MED_SNAME_SIZE*3+1] = "polygon1        polygon2        polygon3        ";
00121 //  med_int numpolygon[3] = {1,9,10};
00122   med_int nufapolygon[3] = {-3,-3,-3};
00123 
00124   /* Mailles POLYEDRE */
00125   med_int npolyhedron = 2;
00126   med_int npolyhedronfaces = 19;
00127   med_int polyhedronconnectivity[74] = {1,2,3,4,5,6,1,7,8,2,2,8,9,3,4,3,9,10,5,4,10,11,6,5,11,12,1,6,12,7,7,12,8,10,9,8,12,11,
00128                                         13,14,15,3,2,13,2,8,16,14,13,16,17,15,14,17,15,17,18,15,18,9,3,15,9,2,3,9,8,8,9,17,16,9,18,17};
00129   med_int polyhedronfacesindex[20] = {1,7,11,15,19,23,27,31,34,
00130                                       39,44,48,52,55,58,61,64,68,72,75};
00131   med_int polyhedronindex[3] = {1,10,20};
00132   //char nompolyhedron[MED_SNAME_SIZE*2+1] = "polyhedron1     polyhedron2     ";
00133 //  med_int numpolyhedron[2] = {2,3};
00134   med_int nufapolyhedron[2] = {-4,-4};
00135 
00136   /* Mailles TETRA4 */
00137   med_int ntetra4 = 1;
00138   med_int tetra4[4] = {
00139     17, 9, 18, 19
00140   };
00141  // char nomtetra4[MED_SNAME_SIZE*1+1] = "tetra1          ";
00142  // med_int numtetra4[1] = {1};
00143   med_int nufatetra4[1] = {-5};
00144 
00145 
00146   char nomfam[MED_NAME_SIZE+1];
00147   med_int numfam;
00148   //char attdesMED_TAILLE_DESC+1];
00149   //med_int attide;
00150   //med_int attval;
00151   char gro[MED_LNAME_SIZE+1];
00152   char dtunitp3[MED_LNAME_SIZE+1]="";
00153 
00154   /*
00155     Some fields : 2 on nodes : one int and one double , one on cells : double
00156    */
00157   char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
00158   char champ1_comp[MED_SNAME_SIZE+1]="comp1           " ;
00159   char champ1_unit[MED_SNAME_SIZE+1]="M               " ;
00160   med_int     fieldnodeint[19]    = {1,1,3,2,2,3,4,4,5,6,6,7,8,8,9,9,9,10,5};
00161 
00162   char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
00163   char champ2_comp[MED_SNAME_SIZE+1]="comp1           " ;
00164   char champ2_unit[MED_SNAME_SIZE+1]="J               " ;
00165   med_float   fieldnodedouble1[19] = {1.,3.,4.,1.,3.,4.,3.,2.,5.,6.,4.,3.,1.,5.,6.,4.,3.,7.,3.};
00166   med_float   fieldnodedouble2[19] = {1.,2.,2.,3.,3.,3.,4.,4.,5.,2.,8.,9.,6.,7.,1.,2.,5.,8.,4.};
00167 
00168   char champ3[MED_NAME_SIZE+1]="fieldfacedouble" ;
00169   char champ3_comp[MED_SNAME_SIZE*2+1]="comp1           comp2           " ;
00170   char champ3_unit[MED_SNAME_SIZE*2+1]="M/S             m/s             " ;
00171   med_float   fieldfacedouble[6*2] = {0.,1.,1.,1.,1.,2.,2.,3.,3.,4.,4.,6.};
00172 
00173   /***************************************************************************/
00174   fid = MEDfileOpen("poly3D.med",MED_ACC_RDWR);
00175   if (fid < 0)
00176     ret = -1;
00177   else
00178     ret = 0;
00179   printf("MEDouvrir : %d\n",ret);
00180 
00181   /***************************************************************************/
00182   if (ret == 0)
00183     ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
00184                     MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
00185   printf("MEDmaaCr : %d\n",ret);
00186   if (ret == 0)
00187     ret = MEDunvCr(fid,maa);
00188   printf("MEDunvCr : %d\n",ret);
00189 
00190   /***************************************************************************/
00191   if (ret == 0)
00192     ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
00193   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
00194   printf("MEDnoeudsEcr : %d\n",ret);
00195 
00196   /* ecriture des faces MED_QUAD4 :
00197      - connectivite
00198      - noms (optionnel) 
00199      - numeros (optionnel)
00200      - numeros des familles */
00201   if (ret == 0) 
00202     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00203                                        MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
00204                                        nquad4,quad4);
00205   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
00206   printf("MEDelementsEcr for quad : %d \n",ret);
00207 
00208   /* ecriture des faces MED_TRIA3 :
00209      - connectivite
00210      - noms (optionnel) 
00211      - numeros (optionnel)
00212      - numeros des familles */
00213   if (ret == 0) 
00214     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00215                                        MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,
00216                                        ntria3,tria3);
00217   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,ntria3,nufatria3);
00218   printf("MEDelementsEcr for tria : %d \n",ret);
00219 
00220   /* ecriture des faces MED_POLYGONE :
00221      - connectivite
00222      - noms (optionnel) 
00223      - numeros (optionnel)
00224      - numeros des familles
00225      Dans ce cas il n existe pas de routine globale (Warning !!) */
00226   if (ret == 0)
00227     ret = MEDmeshPolygonWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT, MED_CELL,MED_NODAL, nindexpolygon,indexpolygon,polygon);
00228   printf("MEDpolygoneConnEcr: %d \n",ret);
00229 
00230 /*   if (ret == 0) */
00231 /*     MEDnomEcr(fid,maa,nompolygon,npolygon,MED_CELL,MED_POLYGONE); */
00232 /*   printf("MEDnomEcr for polygon : %d \n",ret); */
00233 
00234 /*   if (ret == 0) */
00235 /*     MEDnumEcr(fid,maa,numpolygon,npolygon,MED_CELL,MED_POLYGONE); */
00236 /*   printf("MEDnumEcr for polygon : %d \n",ret); */
00237 
00238   if (ret == 0)
00239     MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGON, npolygon,nufapolygon);
00240   printf("MEDfamEcr for polygon : %d \n",ret);
00241 
00242   /* ecriture des mailles MED_POLYEDRE :
00243      - connectivite
00244      - noms (optionnel) 
00245      - numeros (optionnel)
00246      - numeros des familles
00247      Dans ce cas il n existe pas de routine globale (Warning !!) */
00248   if (ret == 0)
00249     ret = MEDmeshPolyhedronWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT, MED_CELL,MED_NODAL, npolyhedronfaces+1,polyhedronfacesindex,npolyhedron+1,polyhedronindex,polyhedronconnectivity);
00250   printf("MEDpolyedreConnEcr: %d \n",ret);
00251 
00252 /*   if (ret == 0) */
00253 /*     ret = MEDnomEcr(fid,maa,nompolyhedron,npolyhedron,MED_CELL,MED_POLYEDRE); */
00254 /*   printf("MEDnomEcr for polyhedron : %d \n",ret); */
00255 
00256 /*   if (ret == 0) */
00257 /*     ret = MEDnumEcr(fid,maa,numpolyhedron,npolyhedron,MED_CELL,MED_POLYEDRE); */
00258 /*   printf("MEDnumEcr for polyhedron : %d \n",ret); */
00259 
00260   if (ret == 0)
00261     ret = MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYHEDRON, npolyhedron,nufapolyhedron);
00262   printf("MEDfamEcr for polyhedron : %d \n",ret);
00263 
00264   /* ecriture des mailles TETRA4 :
00265      - connectivite
00266      - noms (optionnel) 
00267      - numeros (optionnel)
00268      - numeros des familles */
00269   if (ret == 0)
00270     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00271                                        MED_CELL,MED_TETRA4,MED_NODAL,MED_FULL_INTERLACE,
00272                                        ntetra4,tetra4);
00273   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TETRA4,ntetra4,nufatetra4);
00274   printf("MEDelementsEcr for tetra : %d \n",ret);
00275 
00276   /***************************************************************************/
00277   /* ecriture des familles */
00278   /* Conventions :
00279      - toujours creer une famille de numero 0 ne comportant aucun attribut
00280        ni groupe (famille de reference pour les noeuds ou les elements
00281        qui ne sont rattaches a aucun groupe ni attribut)
00282      - les numeros de familles de noeuds sont > 0
00283      - les numeros de familles des elements sont < 0
00284      - rien d'imposer sur les noms de familles
00285    */ 
00286 
00287   /* la famille 0 */
00288   if (ret == 0)
00289     {
00290       strcpy(nomfam,"FAMILLE_0");
00291       numfam = 0;
00292       ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
00293     }
00294   printf("MEDfamCr : %d \n",ret);
00295 
00296   /* on cree :
00297       - 2 familles d'elements de dimension (d)
00298         en fait de face (-10)
00299   */
00300   /*
00301   if (ret == 0)
00302     {
00303       numfam = -1;
00304       strcpy(nomfam,"FAMILLE_FACE_QUAD4");
00305       sprintf(nomfam,"%s%d",nomfam,-numfam);
00306       attide = 1;
00307       attval = numfam*100;
00308       natt = 1;
00309       //strcpy(attdes,"description attribut");
00310       strcpy(gro,"groupe0");
00311       ngro = 1;
00312 
00313       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00314       printf("MEDfamCr : %d\n",ret);
00315 
00316       numfam = -2;
00317       strcpy(nomfam,"FAMILLE_FACE_TRIA3");
00318       sprintf(nomfam,"%s%d",nomfam,-numfam);
00319       attide = 1;
00320       attval = numfam*100;
00321       natt = 1;
00322       //strcpy(attdes,"description attribut");
00323       strcpy(gro,"groupe0");
00324       ngro = 1;
00325 
00326       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00327       printf("MEDfamCr : %d\n",ret);
00328 
00329       numfam = -3;
00330       strcpy(nomfam,"FAMILLE_FACE_POLYGONS");
00331       sprintf(nomfam,"%s%d",nomfam,-numfam);
00332       attide = 1;
00333       attval = numfam*100;
00334       natt = 1;
00335       //strcpy(attdes,"description attribut");
00336       strcpy(gro,"groupe0");
00337       ngro = 1;
00338 
00339       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00340       printf("MEDfamCr : %d\n",ret);
00341 
00342       numfam = -4;
00343       strcpy(nomfam,"FAMILLE_MAILLE_POLYHEDRON");
00344       sprintf(nomfam,"%s%d",nomfam,-numfam);
00345       attide = 1;
00346       attval = numfam*100;
00347       natt = 1;
00348       //strcpy(attdes,"description attribut");
00349       strcpy(gro,"groupe0");
00350       ngro = 1;
00351 
00352       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00353       printf("MEDfamCr : %d\n",ret);
00354 
00355       numfam = -5;
00356       strcpy(nomfam,"FAMILLE_MAILLE_TETRA4");
00357       sprintf(nomfam,"%s%d",nomfam,-numfam);
00358       attide = 1;
00359       attval = numfam*100;
00360       natt = 1;
00361       //strcpy(attdes,"description attribut");
00362       strcpy(gro,"groupe0");
00363       ngro = 1;
00364 
00365       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00366       printf("MEDfamCr : %d\n",ret);
00367     }
00368   */
00369   /***************************************************************************/
00370   /*
00371     Les champs
00372   */
00373   if (ret == 0)
00374     {
00375       ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
00376       printf("MEDchampCr : %d \n",ret);
00377       if (ret == 0) {
00378         ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
00379         
00380         printf("MEDchampEcr : %d \n",ret);
00381       }
00382     }
00383   
00384   if (ret == 0)
00385     {
00386       ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
00387       printf("MEDchampCr : %d \n",ret);
00388       if (ret == 0) {
00389         ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00390         printf("MEDchampEcr1 : %d \n",ret);
00391         ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
00392         printf("MEDchampEcr2 : %d \n",ret);
00393       }
00394     }
00395   
00396   /*/ on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut ! */
00397   if (ret == 0)
00398     {
00399       ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00400       printf("MEDchampEcr : %d \n",ret); 
00401     }
00402 
00403   if (ret == 0)
00404     {
00405       ret = MEDfieldCr(fid,champ3,MED_FLOAT64,2,champ3_comp,champ3_unit,dtunitp3,maa);
00406       printf("MEDchampCr : %d \n",ret);
00407       if (ret == 0) {
00408         ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_TRIA3,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,ntria3, (unsigned char *)fieldfacedouble);
00409         printf("MEDchampEcr : %d \n",ret);
00410       }
00411     }
00412   /***************************************************************************/
00413 
00414   ret = MEDfermer(fid);
00415   printf("MEDfermer : %d\n",ret);
00416   
00417   if ( getenv("srcdir") ) 
00418     /* we are in 'make check' */
00419     remove( "poly3D.med" );
00420 
00421   return 0;
00422 }
00423