Back to index

salome-med  6.5.0
create_poly2D.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 2d : 
00025   maillé en 4 quadrangles reguliers
00026             1 triangle et 1 polygone.
00027 
00028 */
00029 
00030 #include <med.h>
00031 #include <string.h>
00032 
00033 int main (int argc, char **argv)
00034 {
00035   med_err ret;
00036   med_idt fid;
00037   char maa[MED_NAME_SIZE+1] = "poly2D";
00038   char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 2D avec 1 polygone";
00039   med_int mdim = 2;
00040   med_int nnoe = 11;
00041   /*
00042     les noeuds:
00043   */
00044   med_float coo[22] = {
00045     0.0, 0.0,
00046     0.5, 0.0,
00047     1.0, 0.0,
00048     0.25, 0.5,
00049     0.5, 0.5,
00050     0.75, 0.5,
00051     0.0, 1.0,
00052     0.5, 1.0,
00053     1.0, 1.0,
00054     1.5, 0.0,
00055     1.5, 1.0
00056   };
00057   char nomcoo[2*MED_SNAME_SIZE+1] = "x               y               ";
00058   char unicoo[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00059   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
00060   //char *nomnoe ;
00061 //  med_int numnoe[11] = {1,2,3,4,5,6,7,8,9,10,11};
00062   med_int nufano[11] = {0,0,0,0,0,0,0,0,0,0,0};
00063   /*
00064     les elements:
00065   */
00066   med_int nquad4 = 4;
00067   med_int quad4[16] = {
00068     4, 5, 2, 1,
00069     5, 6, 3, 2,
00070     7, 8, 5, 4,
00071     8, 9, 6, 5
00072   };
00073  // char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1           quad2           quad3           quad4           ";
00074  // med_int numquad4[4] = {1,2,3,4};
00075   med_int nufaquad4[4] = {-1,-1,0,0};
00076 
00077   med_int ntria3 = 1;
00078   med_int tria3[3] = {
00079     7, 4, 1
00080   };
00081  // char nomtria3[MED_TAILLE_PNOM+1] = "tria1           ";
00082  // med_int numtria3[1] = {1};
00083   med_int nufatria3[1] = {-2};
00084 
00085   med_int npoly = 1;
00086   med_int nindexpoly = 2;
00087   med_int indexpoly [2] = {
00088     1,6
00089   };
00090   med_int poly[5] = {
00091     9,11,10,3,6
00092   };
00093   char nompoly[MED_TAILLE_PNOM+1] = "poly            ";
00094 //  med_int numpoly[1] = {1};
00095   med_int nufapoly[1] = {-3};
00096 
00097   char nomfam[MED_NAME_SIZE+1];
00098   med_int numfam;
00099   //char attdesMED_TAILLE_DESC+1];
00100   med_int natt;
00101   med_int attide;
00102   med_int attval;
00103   med_int ngro;
00104   char gro[MED_LNAME_SIZE+1];
00105   char dtunitp3[MED_LNAME_SIZE+1]="";
00106   int i;
00107   int nfame = 2; 
00108   int nfamn = 1;
00109 
00110   /*
00111     Some fields : 2 on nodes : one int and one double , one on cells : double
00112    */
00113   char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
00114   char champ1_comp[MED_SNAME_SIZE+1]="comp1           " ;
00115   char champ1_unit[MED_SNAME_SIZE+1]="M               " ;
00116   med_int     fieldnodeint[9]    = {1,1,3,2,2,3,4,4,5};
00117 
00118   char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
00119   char champ2_comp[MED_SNAME_SIZE+1]="comp1           " ;
00120   char champ2_unit[MED_SNAME_SIZE+1]="J               " ;
00121   med_float   fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
00122   med_float   fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
00123 
00124   char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
00125   char champ3_comp[MED_SNAME_SIZE*2+1]="comp1           comp2           " ;
00126   char champ3_unit[MED_SNAME_SIZE*2+1]="M/S             m/s             " ;
00127   med_float   fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
00128 
00129   /***************************************************************************/
00130   fid = MEDfileOpen("poly2D.med",MED_ACC_RDWR);
00131   if (fid < 0)
00132     ret = -1;
00133   else
00134     ret = 0;
00135   printf("MEDouvrir : %d\n",ret);
00136 
00137   /***************************************************************************/
00138   if (ret == 0)
00139     ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
00140                     MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
00141   printf("MEDmaaCr : %d\n",ret);
00142   if (ret == 0)
00143     ret = MEDunvCr(fid,maa);
00144   printf("MEDunvCr : %d\n",ret);
00145 
00146   /***************************************************************************/
00147   if (ret == 0)
00148     ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
00149   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
00150   printf("MEDnoeudsEcr : %d\n",ret);
00151 
00152   /* ecriture des mailles MED_QUAD4 :
00153      - connectivite
00154      - noms (optionnel) 
00155      - numeros (optionnel)
00156      - numeros des familles */
00157   if (ret == 0) 
00158     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00159                                        MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
00160                                        nquad4,quad4);
00161   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
00162   printf("MEDelementsEcr for quad : %d \n",ret);
00163 
00164   /* ecriture des mailles MED_TRIA3 :
00165      - connectivite
00166      - noms (optionnel) 
00167      - numeros (optionnel)
00168      - numeros des familles */
00169   if (ret == 0) 
00170     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00171                                        MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,
00172                                        ntria3,tria3);
00173   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,ntria3,nufatria3);
00174   printf("MEDelementsEcr for tria : %d \n",ret);
00175 
00176   /* ecriture des mailles MED_POLYGONE:
00177      - connectivite
00178      - noms (optionnel) 
00179      - numeros (optionnel)
00180      - numeros des familles
00181      Dans ce cas il n existe pas de routine globale (Warning !!)
00182    */
00183 
00184   if (ret == 0)
00185     ret = MEDpolygoneConnEcr(fid,maa,indexpoly,nindexpoly,poly,
00186                              MED_CELL,MED_NOD);
00187   printf("MEDpolygoneConnEcr: %d \n",ret);
00188 
00189   if (ret == 0)
00190     MEDnomEcr(fid,maa,nompoly,npoly,MED_CELL,MED_POLYGONE);
00191   printf("MEDnomEcr for poly : %d \n",ret);
00192 
00193   if (ret == 0)
00194     MEDnumEcr(fid,maa,numpoly,npoly,MED_CELL,MED_POLYGONE);
00195   printf("MEDnumEcr for poly : %d \n",ret);
00196 
00197   if (ret == 0)
00198     MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGONE, npoly,nufapoly);
00199   printf("MEDfamEcr for poly : %d \n",ret);
00200 
00201 
00202   /***************************************************************************/
00203   /* ecriture des familles */
00204   /* Conventions :
00205      - toujours creer une famille de numero 0 ne comportant aucun attribut
00206        ni groupe (famille de reference pour les noeuds ou les elements
00207        qui ne sont rattaches a aucun groupe ni attribut)
00208      - les numeros de familles de noeuds sont > 0
00209      - les numeros de familles des elements sont < 0
00210      - rien d'imposer sur les noms de familles
00211    */ 
00212 
00213   /* la famille 0 */
00214   if (ret == 0)
00215     {
00216       strcpy(nomfam,"FAMILLE_0");
00217       numfam = 0;
00218       ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
00219     }
00220   printf("MEDfamCr : %d \n",ret);
00221 
00222   /* on cree :
00223       - 2 familles d'elements de dimension (d)
00224         en fait de face (-10)
00225   */
00226   if (ret == 0)
00227     {
00228       numfam = -1;
00229       strcpy(nomfam,"FAMILLE_CELL_");
00230       sprintf(nomfam,"%s%d",nomfam,-numfam);
00231       attide = 1;
00232       attval = numfam*100;
00233       natt = 1;
00234       //strcpy(attdes,"description attribut");
00235       strcpy(gro,"groupe0");
00236       ngro = 1;
00237 
00238       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00239       printf("MEDfamCr : %d\n",ret);
00240 
00241       numfam = -2;
00242       strcpy(nomfam,"FAMILLE_CELL_");
00243       sprintf(nomfam,"%s%d",nomfam,-numfam);
00244       attide = 1;
00245       attval = numfam*100;
00246       natt = 1;
00247       //strcpy(attdes,"description attribut");
00248       strcpy(gro,"groupe0");
00249       ngro = 1;
00250 
00251       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00252       printf("MEDfamCr : %d\n",ret);
00253 
00254       numfam = -3;
00255       strcpy(nomfam,"FAMILLE_CELL_");
00256       sprintf(nomfam,"%s%d",nomfam,-numfam);
00257       attide = 1;
00258       attval = numfam*100;
00259       natt = 1;
00260       //strcpy(attdes,"description attribut");
00261       strcpy(gro,"groupe0");
00262       ngro = 1;
00263 
00264       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00265       printf("MEDfamCr : %d\n",ret);
00266     }
00267 
00268   /***************************************************************************/
00269   /*
00270     Les champs
00271   */
00272   if (ret == 0)
00273     {
00274       ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
00275       printf("MEDchampCr : %d \n",ret);
00276       if (ret == 0) {
00277         ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
00278         
00279         printf("MEDchampEcr : %d \n",ret);
00280       }
00281     }
00282   
00283   if (ret == 0)
00284     {
00285       ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
00286       printf("MEDchampCr : %d \n",ret);
00287       if (ret == 0) {
00288         ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00289         printf("MEDchampEcr1 : %d \n",ret);
00290         ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
00291         printf("MEDchampEcr2 : %d \n",ret);
00292       }
00293     }
00294   
00295   // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
00296   if (ret == 0)
00297     {
00298       ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00299       printf("MEDchampEcr : %d \n",ret); 
00300     }
00301 
00302   if (ret == 0)
00303     {
00304       ret = MEDfieldCr(fid,champ3,MED_FLOAT64,2,champ3_comp,champ3_unit,dtunitp3,maa);
00305       printf("MEDchampCr : %d \n",ret);
00306       if (ret == 0) {
00307         ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_QUAD4,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nquad4, (unsigned char *)fieldcelldouble);
00308         printf("MEDchampEcr : %d \n",ret);
00309       }
00310     }
00311 
00312   /***************************************************************************/
00313 
00314   ret = MEDfermer(fid);
00315   printf("MEDfermer : %d\n",ret);
00316   
00317   return 0;
00318 }
00319