Back to index

salome-med  6.5.0
create_mesh_c3h8q4_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 3d : un cube [0,1]^3
00025   maillé uniformement en hexahedres reguliers;
00026   avec en plus une partie des faces (une partie
00027   des faces 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] = "CUBE_EN_HEXA8_QUAD4_WRONG";
00040   char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 3D";
00041   med_int mdim = 3;
00042   med_int nnoe = 27;
00043   /*
00044     les noeuds:
00045   */
00046   med_float coo[81] = {
00047     0.0, 0.0, 0.0, 
00048     0.5, 0.0, 0.0, 
00049     1.0, 0.0, 0.0, 
00050     0.0, 0.5, 0.0, 
00051     0.5, 0.5, 0.0, 
00052     1.0, 0.5, 0.0, 
00053     0.0, 1.0, 0.0, 
00054     0.5, 1.0, 0.0, 
00055     1.0, 1.0, 0.0, 
00056     0.0, 0.0, 0.5, 
00057     0.5, 0.0, 0.5, 
00058     1.0, 0.0, 0.5, 
00059     0.0, 0.5, 0.5, 
00060     0.5, 0.5, 0.5, 
00061     1.0, 0.5, 0.5, 
00062     0.0, 1.0, 0.5, 
00063     0.5, 1.0, 0.5, 
00064     1.0, 1.0, 0.5, 
00065     0.0, 0.0, 1.0, 
00066     0.5, 0.0, 1.0, 
00067     1.0, 0.0, 1.0, 
00068     0.0, 0.5, 1.0, 
00069     0.5, 0.5, 1.0, 
00070     1.0, 0.5, 1.0, 
00071     0.0, 1.0, 1.0, 
00072     0.5, 1.0, 1.0, 
00073     1.0, 1.0, 1.0
00074   };
00075   char nomcoo[3*MED_SNAME_SIZE+1] = "x               y               z               ";
00076   char unicoo[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
00077   /*  char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1    nom2    nom3    nom4";*/
00078   //char *nomnoe ;
00079 //  med_int numnoe[27] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
00080   med_int nufano[27] = {1,1,1,1,1,1,1,1,1,3,3,3,3,0,3,3,3,3,2,2,2,2,2,2,2,2,2};
00081   /*
00082     les elements:
00083   */
00084   med_int nhexa8 = 8;
00085   med_int hexa8[64] = {
00086     4, 13, 14, 5, 1, 10, 11, 2,
00087     5, 14, 15, 6, 2, 11, 12, 3,
00088     7, 16, 17, 8, 4, 13, 14, 5,
00089     8, 17, 18, 9, 5, 14, 15, 6,
00090     13, 22, 23, 14, 10, 19, 20, 11,
00091     14, 23, 24, 15, 11, 20, 21, 12,
00092     16, 25, 26, 17, 13, 22, 23, 14,
00093     17, 26, 27, 18, 14, 23, 24, 15
00094   };
00095  // char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1           hexa2           hexa3           hexa4           hexa5           hexa6           hexa7           hexa8           ";
00096  // med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
00097   med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
00098 
00099   /*
00100     Les Faces qui dans ce cas (2D) sont des arretes
00101 
00102     a face is wrongly oriented, it is just to test the applidation
00103     duplicateMEDMESH
00104   */
00105 
00106   med_int nquad4 = 8;
00107   med_int quad4[32] = {
00108     20, 21, 24, 23,
00109     22, 23, 26, 25,
00110     19, 20, 23, 22,
00111     23, 24, 27, 26,
00112     /*1 , 4, 5, 2,*/
00113     1 , 2, 5, 4,
00114     5, 8, 9, 6, 
00115     2, 5, 6, 3, 
00116     7, 8, 5, 4
00117   };
00118 
00119  // char nomquad4[MED_TAILLE_PNOM*8+1] = "quad1           quad2           quad3           quad4           quad5           quad6           quad7           quad8          ";
00120  // med_int numquad4[8] = {1,2,3,4,5,6,7,8};
00121   med_int nufaquad4[8] = {-3,-3,-3,-3,-4, -4, -4 , -4};
00122 
00123   char nomfam[MED_NAME_SIZE+1];
00124   med_int numfam;
00125   //char attdesMED_TAILLE_DESC+1];
00126   med_int natt;
00127   med_int attide;
00128   med_int attval;
00129   med_int ngro;
00130   char gro[MED_LNAME_SIZE+1];
00131   char dtunitp3[MED_LNAME_SIZE+1]="";
00132   int i;
00133   int nfame = 1; 
00134   int nfamn = 1;
00135   int nfamf = 1;
00136 
00137   /*
00138     Some fields : 2 on nodes : one int and one double , one on cells : double
00139   */
00140 
00141   char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
00142   char champ1_comp[MED_SNAME_SIZE+1]="comp1           " ;
00143   char champ1_unit[MED_SNAME_SIZE+1]="M               " ;
00144   med_int fieldnodeint[27] = {1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5};
00145 
00146   char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
00147   char champ2_comp[MED_SNAME_SIZE+1]="comp1           " ;
00148   char champ2_unit[MED_SNAME_SIZE+1]="J               " ;
00149   med_float fieldnodedouble1[27] = {1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.};
00150   med_float fieldnodedouble2[27] = {1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.};
00151 
00152   char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
00153   char champ3_comp[MED_SNAME_SIZE*3+1]="comp1           comp2           comp3           " ;
00154   char champ3_unit[MED_SNAME_SIZE*3+1]="M/S             m/s             m/s             " ;
00155   med_float fieldcelldouble[8*3] = {0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.};
00156 
00157   /***************************************************************************/
00158   fid = MEDfileOpen("cube_hexa8_quad4_wrong.med",MED_ACC_RDWR);
00159   if (fid < 0)
00160     ret = -1;
00161   else
00162     ret = 0;
00163   printf("MEDouvrir : %d\n",ret);
00164 
00165   /***************************************************************************/
00166   if (ret == 0)
00167     ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
00168                     MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
00169   printf("MEDmaaCr : %d\n",ret);
00170   if (ret == 0)
00171     ret = MEDunvCr(fid,maa);
00172   printf("MEDunvCr : %d\n",ret);
00173 
00174   /***************************************************************************/
00175   if (ret == 0)
00176     ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
00177   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
00178   printf("MEDnoeudsEcr : %d\n",ret);
00179 
00180   /* ecriture des mailles MED_HEXA8 :
00181      - connectivite
00182      - noms (optionnel) 
00183      - numeros (optionnel)
00184      - numeros des familles */
00185   if (ret == 0) 
00186     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00187                                        MED_CELL,MED_HEXA8,MED_NODAL,MED_FULL_INTERLACE,
00188                                        nhexa8,hexa8);
00189   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_HEXA8,nhexa8,nufahexa8);
00190   printf("MEDelementsEcr : %d \n",ret);
00191 
00192   /* ecriture des mailles MED_QUAD4 :
00193      - connectivite
00194      - noms (optionnel) 
00195      - numeros (optionnel)
00196      - numeros des familles */
00197   if (ret == 0) 
00198     ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
00199                                        MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
00200                                        nquad4,quad4);
00201   MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
00202   printf("MEDelementsEcr : %d \n",ret);
00203 
00204   /***************************************************************************/
00205   /* ecriture des familles */
00206   /* Conventions :
00207      - toujours creer une famille de numero 0 ne comportant aucun attribut
00208        ni groupe (famille de reference pour les noeuds ou les elements
00209        qui ne sont rattaches a aucun groupe ni attribut)
00210      - les numeros de familles de noeuds sont > 0
00211      - les numeros de familles des elements sont < 0
00212      - rien d'imposer sur les noms de familles
00213    */ 
00214 
00215   /* la famille 0 */
00216   if (ret == 0)
00217     {
00218       strcpy(nomfam,"FAMILLE_0");
00219       numfam = 0;
00220       ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
00221     }
00222   printf("%d \n",ret);
00223 
00224   /* on cree :
00225       - 2 familles d'elements (-1,-2) et 
00226       - 3 familles de noeuds (1,2,3) 
00227       - 1 famille(s) d'elements de dimension (d-1)
00228         en fait de face (-3)
00229   */
00230 
00231   if (ret == 0)
00232     {
00233       nfame = 2;
00234       for (i=0;i<nfame;i++)
00235         {
00236           if (ret == 0)
00237             {
00238               strcpy(nomfam,"FAMILLE_ELEMENT_");
00239               numfam = -(i+1);
00240               sprintf(nomfam,"%s%d",nomfam,-numfam);
00241               attide = 1;
00242               attval = numfam*100;
00243               natt = 1;
00244               //strcpy(attdes,"description attribut");
00245               strcpy(gro,"groupe1");
00246               ngro = 1;
00247 
00248               /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
00249 
00250               ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00251               printf("MEDfamCr : %d\n",ret);
00252             }
00253         }
00254     }
00255   
00256   if (ret == 0)
00257     {
00258       nfamn = 3;
00259       for (i=0;i<nfamn;i++)
00260         {
00261           if(ret == 0)
00262             {
00263               strcpy(nomfam,"FAMILLE_NOEUD_");
00264               numfam = i+1;
00265               sprintf(nomfam,"%s%d",nomfam,numfam);
00266               attide = 1;
00267               attval = numfam*100;
00268               natt = 1;
00269               //strcpy(attdes,"description attribut");
00270               strcpy(gro,"groupe2");
00271               ngro = 1;
00272               ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00273               printf("MEDfamCr : %d\n",ret);
00274             }
00275         }
00276     }
00277 
00278   if (ret == 0)
00279     {
00280       nfamf = 2;
00281       for (i=0;i<nfamf;i++)
00282         {
00283           if (ret == 0)
00284             {
00285               strcpy(nomfam,"FAMILLE_FACE_");
00286               numfam = -(i+3);
00287               sprintf(nomfam,"%s%d",nomfam,-numfam);
00288               attide = 1;
00289               attval = numfam*100;
00290               natt = 1;
00291               //strcpy(attdes,"description attribut");
00292               strcpy(gro,"groupe3");
00293               ngro = 1;
00294               /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
00295               ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
00296               printf("MEDfamCr : %d\n",ret);
00297             }
00298         }
00299     }
00300 
00301   /***************************************************************************/
00302   /*
00303     Les champs
00304   */
00305   if (ret == 0)
00306     {
00307       ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
00308       printf("MEDchampCr : %d \n",ret);
00309       if (ret == 0) {
00310         ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
00311         
00312         printf("MEDchampEcr : %d \n",ret);
00313       }
00314     }
00315   
00316   if (ret == 0)
00317     {
00318       ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
00319       printf("MEDchampCr : %d \n",ret);
00320       if (ret == 0) {
00321         ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00322         printf("MEDchampEcr1 : %d \n",ret);
00323         ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
00324         printf("MEDchampEcr2 : %d \n",ret);
00325       }
00326     }
00327   
00328   /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
00329   if (ret == 0)
00330     {
00331       ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
00332       printf("MEDchampEcr : %d \n",ret); 
00333     }
00334 
00335   if (ret == 0)
00336     {
00337       ret = MEDfieldCr(fid,champ3,MED_FLOAT64,3,champ3_comp,champ3_unit,dtunitp3,maa);
00338       printf("MEDchampCr : %d \n",ret);
00339       if (ret == 0) {
00340         ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_HEXA8,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nhexa8, (unsigned char *)fieldcelldouble);
00341         printf("MEDchampEcr : %d \n",ret);
00342       }
00343     }
00344 
00345   /***************************************************************************/
00346 
00347   ret = MEDfermer(fid);
00348   printf("%d\n",ret);
00349   
00350   if ( getenv("srcdir") ) 
00351     /* we are in 'make check' */
00352     remove( "cube_hexa8_quad4_wrong.med" );
00353 
00354   return 0;
00355 }