1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 creation d'une geometrie 3d : un cube [0,1]^3
24 maillé uniformement en hexahedres reguliers;
25 avec en plus une partie des faces (une partie
26 des faces de la frontiere) du maillage.
27 ATTENTION : 3 noeuds dans chaque direction
33 int main (int argc, char **argv)
37 char maa[MED_TAILLE_NOM+1] = "CUBE_EN_HEXA8";
38 char maadesc[MED_TAILLE_DESC+1] = "Example de maillage non structure 3D";
73 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
74 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
75 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
77 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};
78 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};
84 4, 13, 14, 5, 1, 10, 11, 2,
85 5, 14, 15, 6, 2, 11, 12, 3,
86 7, 16, 17, 8, 4, 13, 14, 5,
87 8, 17, 18, 9, 5, 14, 15, 6,
88 13, 22, 23, 14, 10, 19, 20, 11,
89 14, 23, 24, 15, 11, 20, 21, 12,
90 16, 25, 26, 17, 13, 22, 23, 14,
91 17, 26, 27, 18, 14, 23, 24, 15
93 char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1 hexa2 hexa3 hexa4 hexa5 hexa6 hexa7 hexa8 ";
94 med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
95 med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
97 char nomfam[MED_TAILLE_NOM+1];
99 char attdes[MED_TAILLE_DESC+1];
104 char gro[MED_TAILLE_LNOM+1];
111 Some fields : 2 on nodes : one int and one double , one on cells : double
114 char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
115 char champ1_comp[MED_TAILLE_PNOM+1]="comp1 " ;
116 char champ1_unit[MED_TAILLE_PNOM+1]="M " ;
117 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};
119 char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
120 char champ2_comp[MED_TAILLE_PNOM+1]="comp1 " ;
121 char champ2_unit[MED_TAILLE_PNOM+1]="J " ;
122 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.};
123 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.};
125 char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
126 char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1 comp2 comp3 " ;
127 char champ3_unit[MED_TAILLE_PNOM*3+1]="M/S m/s m/s " ;
128 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.};
130 /***************************************************************************/
131 fid = MEDouvrir("cube_hexa8.med",MED_LECTURE_ECRITURE);
136 printf("MEDouvrir : %d\n",ret);
138 /***************************************************************************/
140 ret = MEDmaaCr(fid,maa,mdim,MED_NON_STRUCTURE,maadesc);
141 printf("MEDmaaCr : %d\n",ret);
143 ret = MEDunvCr(fid,maa);
144 printf("MEDunvCr : %d\n",ret);
146 /***************************************************************************/
148 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
149 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
151 printf("MEDnoeudsEcr : %d\n",ret);
153 /* ecriture des mailles MED_HEXA8 :
156 - numeros (optionnel)
157 - numeros des familles */
159 ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
160 nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
161 MED_MAILLE,MED_HEXA8,MED_NOD);
162 printf("MEDelementsEcr : %d \n",ret);
164 /***************************************************************************/
165 /* ecriture des familles */
167 - toujours creer une famille de numero 0 ne comportant aucun attribut
168 ni groupe (famille de reference pour les noeuds ou les elements
169 qui ne sont rattaches a aucun groupe ni attribut)
170 - les numeros de familles de noeuds sont > 0
171 - les numeros de familles des elements sont < 0
172 - rien d'imposer sur les noms de familles
178 strcpy(nomfam,"FAMILLE_0");
180 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
186 - 2 familles d'elements (-1,-2) et
187 - 3 familles de noeuds (1,2,3)
193 for (i=0;i<nfame;i++)
197 strcpy(nomfam,"FAMILLE_ELEMENT_");
199 sprintf(nomfam,"%s%d",nomfam,-numfam);
203 strcpy(attdes,"description attribut");
204 strcpy(gro,"groupe1");
207 /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
209 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
211 printf("MEDfamCr : %d\n",ret);
219 for (i=0;i<nfamn;i++)
223 strcpy(nomfam,"FAMILLE_NOEUD_");
225 sprintf(nomfam,"%s%d",nomfam,numfam);
229 strcpy(attdes,"description attribut");
230 strcpy(gro,"groupe2");
232 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
234 printf("MEDfamCr : %d\n",ret);
239 /***************************************************************************/
245 ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
246 printf("MEDchampCr : %d \n",ret);
248 ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
249 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
250 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
251 MED_NOPDT," ", 0., MED_NONOR);
253 printf("MEDchampEcr : %d \n",ret);
259 ret = MEDchampCr(fid,champ2,MED_FLOAT64,champ2_comp,champ2_unit,1);
260 printf("MEDchampCr : %d \n",ret);
262 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
263 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
264 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
265 1,"S ", 1.1 , MED_NONOR);
266 printf("MEDchampEcr1 : %d \n",ret);
267 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
268 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
269 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
270 2,"S ", 1.2 , MED_NONOR);
271 printf("MEDchampEcr2 : %d \n",ret);
275 /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
278 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
279 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
280 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
281 MED_NOPDT," ", 0. , MED_NONOR);
282 printf("MEDchampEcr : %d \n",ret);
287 ret = MEDchampCr(fid,champ3,MED_FLOAT64,champ3_comp,champ3_unit,3);
288 printf("MEDchampCr : %d \n",ret);
290 ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
291 MED_FULL_INTERLACE, nhexa8, MED_NOGAUSS, MED_ALL,
292 MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE, MED_HEXA8,
293 MED_NOPDT," ", 0., MED_NONOR);
294 printf("MEDchampEcr : %d \n",ret);
298 /***************************************************************************/
300 ret = MEDfermer(fid);
303 if ( getenv("srcdir") )
304 /* we are in 'make check' */
305 remove( "cube_hexa8.med" );