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 2d : un cube [0,1]^2
24 maillé uniformement en triangles reguliers;
25 avec n (=argv[1]) noeuds dans chaque direction.
27 - DbleVectNode champ vectoriel reel sur les noeuds
28 - DbleVectCell champ vectoriel reel sur les cellules
30 En sortie, il y aura production d'un fichier MED
31 carre_tria3_n.med qui contiendra un seul maillage et 2 champs
32 avec une seule famille la FAMILLE_0
41 int main (int argc, char **argv)
45 char maa[MED_TAILLE_NOM+1] = "carre_tria3";
59 med_float * DbleVectNode;
60 med_float * DbleVectCell;
68 char nomcoo[2*MED_TAILLE_PNOM+1] = "x y ";
69 char unicoo[2*MED_TAILLE_PNOM+1] = "cm cm ";
70 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
78 int indexN1, indexN2, indexN3, indexN4;
80 char nomfam[MED_TAILLE_NOM+1];
82 char attdes[MED_TAILLE_DESC+1];
87 char gro[MED_TAILLE_LNOM+1];
91 char MedFile[100] = "carre_tria3_";
98 char champDbleVectNode[MED_TAILLE_NOM+1] = "DbleVectNode";
99 char compDbleVectNode[MED_TAILLE_PNOM*2+1] = "comp1 comp2 " ;
100 char unitDbleVectNode[MED_TAILLE_PNOM*2+1] = "unit1 unit2 " ;
102 char champDbleVectCell[MED_TAILLE_NOM+1] = "DbleVectCell";
103 char compDbleVectCell[MED_TAILLE_PNOM*2+1] = "comp1 comp2 " ;
104 char unitDbleVectCell[MED_TAILLE_PNOM*2+1] = "unit1 unit2 " ;
108 printf("Usage: %s <n> \n",argv[0]);
110 printf(" - n is the number of nodes in each direction.\n");
112 printf("This program will produce a MED file carre_tria3_n.med\n");
116 nnoe_dir = atoi(argv[1]);
117 nelt_dir = nnoe_dir-1;
118 nnoe = nnoe_dir*nnoe_dir;
120 coo = malloc(mdim*nnoe*sizeof(med_float));
121 numnoe = malloc(nnoe*sizeof(med_int));
122 nufano = malloc(nnoe*sizeof(med_int));
123 nomnoe = malloc((MED_TAILLE_PNOM*nnoe+1)*sizeof(char));
125 hxsize = 1./((med_float) (nnoe_dir - 1));
128 ntria3 = 2*nelt_dir*nelt_dir;
129 tria3 = malloc(3*ntria3*sizeof(med_int));
130 numtria3 = malloc(ntria3*sizeof(med_int));
131 nufatria3 = malloc(ntria3*sizeof(med_int));
132 nomtria3 = malloc((MED_TAILLE_PNOM*ntria3+1)*sizeof(char));
134 DbleVectNode = malloc(mdim*nnoe*sizeof(med_float));
135 DbleVectCell = malloc(mdim*ntria3*sizeof(med_float));
141 for(j=0;j<nnoe_dir;j++)
143 for (i=0;i<nnoe_dir;i++)
145 int ij = j*nnoe_dir+i;
150 coo[mdim*ij] = ((med_float) i)*hxsize;
151 coo[mdim*ij+1] = ((med_float) j)*hysize;
154 printf("Coordonnées %d X = %lf Y = %lf\n",(ij+1),coo[mdim*ij],coo[mdim*ij+1]);
163 for(j=0;j<nelt_dir;j++)
165 for (i=0;i<nelt_dir;i++)
167 int ij = j*nelt_dir+i;
171 numtria3[ij1] = ij1+1;
172 numtria3[ij2] = ij2+1;
177 indexN4 = j*nnoe_dir+i+1;
179 indexN1 = indexN4+nnoe_dir;
180 indexN2 = indexN3+nnoe_dir;
182 tria3[3*ij1] = indexN1;
183 tria3[3*ij1+1] = indexN2;
184 tria3[3*ij1+2] = indexN3;
186 tria3[3*ij2] = indexN1;
187 tria3[3*ij2+1] = indexN3;
188 tria3[3*ij2+2] = indexN4;
193 for (i=0;i<ntria3;i++)
195 printf("Connectivitée %d i1 = %d i2 = %d i3 = %d\n",(i+1),tria3[3*i],tria3[3*i+1],tria3[3*i+2]);
205 srand((int) t1); /* use time in seconds to set seed */
209 DbleVectNode[mdim*i] =
210 (med_float) (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
212 DbleVectNode[mdim*i+1] =
213 (med_float) (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
216 printf("i %d DbleVectNode %lf %lf\n",i,DbleVectNode[mdim*i],
217 DbleVectNode[mdim*i+1]);
221 for(i=0;i<ntria3;i++)
223 DbleVectCell[mdim*i] = (med_float)
224 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
226 DbleVectCell[mdim*i+1] = (med_float)
227 (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
230 printf("i %d DbleVectCell %lf %lf\n",i,DbleVectCell[mdim*i],
231 DbleVectCell[mdim*i+1]);
235 /***************************************************************************/
237 sprintf(buff,"%d",nnoe_dir);
238 strcat(MedFile,buff);
239 strcat(MedFile,".med");
241 fid = MEDouvrir(MedFile,RDWR);
249 /***************************************************************************/
251 ret = MEDmaaCr(fid,maa,mdim);
255 ret = MEDunvCr(fid,maa);
258 /***************************************************************************/
261 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
262 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
267 ecriture des mailles MED_TRIA3 :
270 - numeros (optionnel)
271 - numeros des familles
275 ret = MEDelementsEcr(fid,maa,mdim,tria3,MED_FULL_INTERLACE,
276 nomtria3,MED_FAUX,numtria3,MED_VRAI,nufatria3,ntria3,
277 MED_MAILLE,MED_TRIA3,MED_NOD,WRONLY);
280 /***************************************************************************/
281 /* ecriture des familles */
283 - toujours creer une famille de numero 0 ne comportant aucun attribut
284 ni groupe (famille de reference pour les noeuds ou les elements
285 qui ne sont rattaches a aucun groupe ni attribut)
286 - les numeros de familles de noeuds sont > 0
287 - les numeros de familles des elements sont < 0
288 - rien d'imposer sur les noms de familles
294 strcpy(nomfam,"FAMILLE_0");
296 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
301 /***************************************************************************/
308 ret = MEDchampCr(fid,champDbleVectNode,MED_REEL64,compDbleVectNode,
309 unitDbleVectNode,mdim);
311 printf("MEDchampCr DbleVectNode : %d \n",ret);
315 ret = MEDchampEcr(fid, maa, champDbleVectNode,
316 (unsigned char *)DbleVectNode,
317 MED_NO_INTERLACE, nnoe,
318 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_NOEUD,
319 0, MED_NOPDT," ", 0., MED_NONOR);
321 printf("MEDchampEcr DbleVectNode : %d \n",ret);
328 ret = MEDchampCr(fid,champDbleVectCell,MED_REEL64,compDbleVectCell,
329 unitDbleVectCell,mdim);
331 printf("MEDchampCr DbleVectCell : %d \n",ret);
335 ret = MEDchampEcr(fid, maa, champDbleVectCell,
336 (unsigned char *)DbleVectCell,
337 MED_NO_INTERLACE, ntria3,
338 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_MAILLE,
339 MED_TRIA3, MED_NOPDT," ", 0., MED_NONOR);
341 printf("MEDchampEcr DbleVectCell : %d \n",ret);
345 /***************************************************************************/
347 ret = MEDfermer(fid);