Back to index

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