1 // Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 // PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 creation d'une geometrie 3d : un cube [0,1]^3
21 maillé uniformement en hexahedres reguliers;
22 avec en plus une partie des faces (une partie
23 des faces de la frontiere) du maillage.
24 ATTENTION : 3 noeuds dans chaque direction
30 int main (int argc, char **argv)
34 char maa[MED_TAILLE_NOM+1] = "CUBE_EN_HEXA8";
35 char maadesc[MED_TAILLE_DESC+1] = "Example de maillage non structure 3D";
70 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
71 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
72 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
74 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};
75 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};
81 4, 13, 14, 5, 1, 10, 11, 2,
82 5, 14, 15, 6, 2, 11, 12, 3,
83 7, 16, 17, 8, 4, 13, 14, 5,
84 8, 17, 18, 9, 5, 14, 15, 6,
85 13, 22, 23, 14, 10, 19, 20, 11,
86 14, 23, 24, 15, 11, 20, 21, 12,
87 16, 25, 26, 17, 13, 22, 23, 14,
88 17, 26, 27, 18, 14, 23, 24, 15
90 char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1 hexa2 hexa3 hexa4 hexa5 hexa6 hexa7 hexa8 ";
91 med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
92 med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
94 char nomfam[MED_TAILLE_NOM+1];
96 char attdes[MED_TAILLE_DESC+1];
101 char gro[MED_TAILLE_LNOM+1];
108 Some fields : 2 on nodes : one int and one double , one on cells : double
111 char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
112 char champ1_comp[MED_TAILLE_PNOM+1]="comp1 " ;
113 char champ1_unit[MED_TAILLE_PNOM+1]="M " ;
114 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};
116 char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
117 char champ2_comp[MED_TAILLE_PNOM+1]="comp1 " ;
118 char champ2_unit[MED_TAILLE_PNOM+1]="J " ;
119 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.};
120 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.};
122 char champ3[MED_TAILLE_NOM+1]="fieldcelldouble" ;
123 char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1 comp2 comp3 " ;
124 char champ3_unit[MED_TAILLE_PNOM*3+1]="M/S m/s m/s " ;
125 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.};
127 /***************************************************************************/
128 fid = MEDouvrir("cube_hexa8.med",MED_LECTURE_ECRITURE);
133 printf("MEDouvrir : %d\n",ret);
135 /***************************************************************************/
137 ret = MEDmaaCr(fid,maa,mdim,MED_NON_STRUCTURE,maadesc);
138 printf("MEDmaaCr : %d\n",ret);
140 ret = MEDunvCr(fid,maa);
141 printf("MEDunvCr : %d\n",ret);
143 /***************************************************************************/
145 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
146 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
148 printf("MEDnoeudsEcr : %d\n",ret);
150 /* ecriture des mailles MED_HEXA8 :
153 - numeros (optionnel)
154 - numeros des familles */
156 ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
157 nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
158 MED_MAILLE,MED_HEXA8,MED_NOD);
159 printf("MEDelementsEcr : %d \n",ret);
161 /***************************************************************************/
162 /* ecriture des familles */
164 - toujours creer une famille de numero 0 ne comportant aucun attribut
165 ni groupe (famille de reference pour les noeuds ou les elements
166 qui ne sont rattaches a aucun groupe ni attribut)
167 - les numeros de familles de noeuds sont > 0
168 - les numeros de familles des elements sont < 0
169 - rien d'imposer sur les noms de familles
175 strcpy(nomfam,"FAMILLE_0");
177 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
183 - 2 familles d'elements (-1,-2) et
184 - 3 familles de noeuds (1,2,3)
190 for (i=0;i<nfame;i++)
194 strcpy(nomfam,"FAMILLE_ELEMENT_");
196 sprintf(nomfam,"%s%d",nomfam,-numfam);
200 strcpy(attdes,"description attribut");
201 strcpy(gro,"groupe1");
204 /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
206 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
208 printf("MEDfamCr : %d\n",ret);
216 for (i=0;i<nfamn;i++)
220 strcpy(nomfam,"FAMILLE_NOEUD_");
222 sprintf(nomfam,"%s%d",nomfam,numfam);
226 strcpy(attdes,"description attribut");
227 strcpy(gro,"groupe2");
229 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
231 printf("MEDfamCr : %d\n",ret);
236 /***************************************************************************/
242 ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
243 printf("MEDchampCr : %d \n",ret);
245 ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
246 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
247 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
248 MED_NOPDT," ", 0., MED_NONOR);
250 printf("MEDchampEcr : %d \n",ret);
256 ret = MEDchampCr(fid,champ2,MED_FLOAT64,champ2_comp,champ2_unit,1);
257 printf("MEDchampCr : %d \n",ret);
259 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
260 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
261 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
262 1,"S ", 1.1 , MED_NONOR);
263 printf("MEDchampEcr1 : %d \n",ret);
264 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
265 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
266 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
267 2,"S ", 1.2 , MED_NONOR);
268 printf("MEDchampEcr2 : %d \n",ret);
272 /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
275 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
276 MED_FULL_INTERLACE, nnoe, MED_NOGAUSS, MED_ALL,
277 MED_NOPFL, MED_NO_PFLMOD, MED_NOEUD, 0,
278 MED_NOPDT," ", 0. , MED_NONOR);
279 printf("MEDchampEcr : %d \n",ret);
284 ret = MEDchampCr(fid,champ3,MED_FLOAT64,champ3_comp,champ3_unit,3);
285 printf("MEDchampCr : %d \n",ret);
287 ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble,
288 MED_FULL_INTERLACE, nhexa8, MED_NOGAUSS, MED_ALL,
289 MED_NOPFL, MED_NO_PFLMOD, MED_MAILLE, MED_HEXA8,
290 MED_NOPDT," ", 0., MED_NONOR);
291 printf("MEDchampEcr : %d \n",ret);
295 /***************************************************************************/
297 ret = MEDfermer(fid);