Back to index

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