Back to index

salome-med  6.5.0
create_mesh_c2q4.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";
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] = {-1,-1,0,0};
00075 
00076   char nomfam[MED_NAME_SIZE+1];
00077   med_int numfam;
00078   //char attdesMED_TAILLE_DESC+1];
00079   med_int natt;
00080   med_int attide;
00081   med_int attval;
00082   med_int ngro;
00083   char gro[MED_LNAME_SIZE+1];
00084   char dtunitp3[MED_LNAME_SIZE+1]="";
00085 
00086   /*
00087     Some fields : 2 on nodes : one int and one double , one on cells : double
00088    */
00089   char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
00090   char champ1_comp[MED_SNAME_SIZE+1]="comp1           " ;
00091   char champ1_unit[MED_SNAME_SIZE+1]="M               " ;
00092   med_int     fieldnodeint[9]    = {1,1,3,2,2,3,4,4,5};
00093 
00094   char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
00095   char champ2_comp[MED_SNAME_SIZE+1]="comp1           " ;
00096   char champ2_unit[MED_SNAME_SIZE+1]="J               " ;
00097   med_float   fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
00098   med_float   fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
00099 
00100   char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
00101   char champ3_comp[MED_SNAME_SIZE*2+1]="comp1           comp2           " ;
00102   char champ3_unit[MED_SNAME_SIZE*2+1]="M/S             m/s             " ;
00103   med_float   fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
00104 
00105   /***************************************************************************/
00106   fid = MEDfileOpen("carre_en_quad4.med",MED_ACC_RDWR);
00107   if (fid < 0)
00108     ret = -1;
00109   else
00110     ret = 0;
00111   printf("MEDouvrir : %d\n",ret);
00112 
00113   /***************************************************************************/
00114   if (ret == 0)
00115     ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
00116                     MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
00117   printf("MEDmaaCr : %d\n",ret);
00118   if (ret == 0)
00119     ret = MEDunvCr(fid,maa);
00120   printf("MEDunvCr : %d\n",ret);
00121 
00122   /***************************************************************************/
00123   if (ret == 0)
00124     ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
00125   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
00126   printf("MEDnoeudsEcr : %d\n",ret);
00127 
00128   /* ecriture des mailles MED_QUAD4 :
00129      - connectivite
00130      - noms (optionnel) 
00131      - numeros (optionnel)
00132      - numeros des familles */
00133   if (ret == 0) 
00134     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00135                                        MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
00136                                        nquad4,quad4);
00137   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
00138   printf("MEDelementsEcr : %d \n",ret);
00139 
00140   /***************************************************************************/
00141   /* ecriture des familles */
00142   /* Conventions :
00143      - toujours creer une famille de numero 0 ne comportant aucun attribut
00144        ni groupe (famille de reference pour les noeuds ou les elements
00145        qui ne sont rattaches a aucun groupe ni attribut)
00146      - les numeros de familles de noeuds sont > 0
00147      - les numeros de familles des elements sont < 0
00148      - rien d'imposer sur les noms de familles
00149    */ 
00150 
00151   /* la famille 0 */
00152   if (ret == 0)
00153     {
00154       strcpy(nomfam,"FAMILLE_0");
00155       numfam = 0;
00156       ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
00157     }
00158   printf("MEDfamCr : %d \n",ret);
00159 
00160   /* on cree :
00161       - 1 familles d'elements de dimension (d)
00162         en fait de face (-10)
00163   */
00164 
00165   if (ret == 0)
00166     {
00167       numfam = -1;
00168       strcpy(nomfam,"FAMILLE_CELL_");
00169       sprintf(nomfam,"%s%d",nomfam,-numfam);
00170       attide = 1;
00171       attval = numfam*100;
00172       natt = 1;
00173       //strcpy(attdes,"description attribut");
00174       strcpy(gro,"groupe0");
00175       ngro = 1;
00176 
00177       ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00178       printf("MEDfamCr : %d\n",ret);
00179     }
00180   /***************************************************************************/
00181   /*
00182     Les champs
00183   */
00184   if (ret == 0)
00185     {
00186       ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
00187       printf("MEDchampCr : %d \n",ret);
00188       if (ret == 0) {
00189         ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
00190         
00191         printf("MEDchampEcr : %d \n",ret);
00192       }
00193     }
00194   
00195   if (ret == 0)
00196     {
00197       ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
00198       printf("MEDchampCr : %d \n",ret);
00199       if (ret == 0) {
00200         ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00201         printf("MEDchampEcr1 : %d \n",ret);
00202         ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
00203         printf("MEDchampEcr2 : %d \n",ret);
00204       }
00205     }
00206   
00207   /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut ! */
00208   if (ret == 0)
00209     {
00210       ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00211       printf("MEDchampEcr : %d \n",ret); 
00212     }
00213 
00214   if (ret == 0)
00215     {
00216       ret = MEDfieldCr(fid,champ3,MED_FLOAT64,2,champ3_comp,champ3_unit,dtunitp3,maa);
00217       printf("MEDchampCr : %d \n",ret);
00218       if (ret == 0) {
00219         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);
00220         printf("MEDchampEcr : %d \n",ret);
00221       }
00222     }
00223   
00224   /***************************************************************************/
00225 
00226   ret = MEDfermer(fid);
00227   printf("MEDfermer : %d\n",ret);
00228 
00229   if ( getenv("srcdir") ) 
00230     /* we are in 'make check' */
00231     remove( "carre_en_quad4.med" );
00232   
00233   return 0;
00234 }