1 // Copyright (C) 2007-2013 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
24 creation d'une geometrie 2d : un cube [0,1]^2
25 maillé uniformement en quadrangle reguliers;
26 avec n (=argv[1]) noeuds dans chaque direction.
28 - DbleVectNode champ vectoriel reel sur les noeuds
29 - DbleVectCell champ vectoriel reel sur les cellules
31 En sortie, il y aura production d'un fichier MED
32 carre_quad4_n.med qui contiendra un seul maillage et 2 champs
33 avec une seule famille la FAMILLE_0
42 int main (int argc, char **argv)
46 char maa[MED_TAILLE_NOM+1] = "carre_quad4";
60 med_float * DbleVectNode;
61 med_float * DbleVectCell;
69 char nomcoo[2*MED_TAILLE_PNOM+1] = "x y ";
70 char unicoo[2*MED_TAILLE_PNOM+1] = "cm cm ";
71 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
78 /* char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1 quad2 quad3 quad4 ";*/
80 int indexN1, indexN2, indexN3, indexN4;
82 char nomfam[MED_TAILLE_NOM+1];
84 char attdes[MED_TAILLE_DESC+1];
89 char gro[MED_TAILLE_LNOM+1];
93 char MedFile[100] = "carre_quad4_";
100 char champDbleVectNode[MED_TAILLE_NOM+1] = "DbleVectNode";
101 char compDbleVectNode[MED_TAILLE_PNOM*2+1] = "comp1 comp2 " ;
102 char unitDbleVectNode[MED_TAILLE_PNOM*2+1] = "unit1 unit2 " ;
104 char champDbleVectCell[MED_TAILLE_NOM+1] = "DbleVectCell";
105 char compDbleVectCell[MED_TAILLE_PNOM*2+1] = "comp1 comp2 " ;
106 char unitDbleVectCell[MED_TAILLE_PNOM*2+1] = "unit1 unit2 " ;
110 printf("Usage: %s <n> \n",argv[0]);
112 printf(" - n is the number of nodes in each direction.\n");
114 printf("This program will produce a MED file carre_quad4_n.med\n");
118 nnoe_dir = atoi(argv[1]);
119 nelt_dir = nnoe_dir-1;
120 nnoe = nnoe_dir*nnoe_dir;
122 coo = malloc(mdim*nnoe*sizeof(med_float));
123 numnoe = malloc(nnoe*sizeof(med_int));
124 nufano = malloc(nnoe*sizeof(med_int));
125 nomnoe = malloc((MED_TAILLE_PNOM*nnoe+1)*sizeof(char));
127 hxsize = 1./((med_float) (nnoe_dir - 1));
130 nquad4 = nelt_dir*nelt_dir;
131 quad4 = malloc(4*nquad4*sizeof(med_int));
132 numquad4 = malloc(nquad4*sizeof(med_int));
133 nufaquad4 = malloc(nquad4*sizeof(med_int));
134 nomquad4 = malloc((MED_TAILLE_PNOM*nquad4+1)*sizeof(char));
136 DbleVectNode = malloc(mdim*nnoe*sizeof(med_float));
137 DbleVectCell = malloc(mdim*nquad4*sizeof(med_float));
143 for(j=0;j<nnoe_dir;j++)
145 for (i=0;i<nnoe_dir;i++)
147 int ij = j*nnoe_dir+i;
152 coo[mdim*ij] = ((med_float) i)*hxsize;
153 coo[mdim*ij+1] = ((med_float) j)*hysize;
156 printf("Coordonnées %d X = %lf Y = %lf\n",(ij+1),coo[mdim*ij],coo[mdim*ij+1]);
165 for(j=0;j<nelt_dir;j++)
167 for (i=0;i<nelt_dir;i++)
169 int ij = j*nelt_dir+i;
174 indexN4 = j*nnoe_dir+i+1;
176 indexN1 = indexN4+nnoe_dir;
177 indexN2 = indexN3+nnoe_dir;
179 quad4[4*ij] = indexN1;
180 quad4[4*ij+1] = indexN2;
181 quad4[4*ij+2] = indexN3;
182 quad4[4*ij+3] = indexN4;
185 printf("Connectivitée %d i1 = %d i2 = %d i3 = %d i4 = %d\n",(ij+1),quad4[4*ij],quad4[4*ij+1],quad4[4*ij+2],quad4[4*ij+3]);
197 srand((int) t1); /* use time in seconds to set seed */
201 DbleVectNode[mdim*i] =
202 (med_float) (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
204 DbleVectNode[mdim*i+1] =
205 (med_float) (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
208 printf("i %d DbleVectNode %lf %lf\n",i,DbleVectNode[mdim*i],
209 DbleVectNode[mdim*i+1]);
213 for(i=0;i<nquad4;i++)
215 DbleVectCell[mdim*i] =
216 (med_float) (1+(int) (100.0*rand()/(RAND_MAX+1.0)));
218 DbleVectCell[mdim*i+1] =
219 (med_float) (1+(int) (1000*rand()/(RAND_MAX+1.0)));
222 printf("i %d DbleVectCell %lf %lf\n",i,DbleVectCell[mdim*i],
223 DbleVectCell[mdim*i+1]);
227 /***************************************************************************/
229 sprintf(buff,"%d",nnoe_dir);
230 strcat(MedFile,buff);
231 strcat(MedFile,".med");
233 fid = MEDouvrir(MedFile,RDWR);
241 /***************************************************************************/
243 ret = MEDmaaCr(fid,maa,mdim);
247 ret = MEDunvCr(fid,maa);
250 /***************************************************************************/
253 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
254 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
259 ecriture des mailles MED_QUAD4 :
262 - numeros (optionnel)
263 - numeros des familles
267 ret = MEDelementsEcr(fid,maa,mdim,quad4,MED_FULL_INTERLACE,
268 nomquad4,MED_FAUX,numquad4,MED_VRAI,nufaquad4,nquad4,
269 MED_MAILLE,MED_QUAD4,MED_NOD,WRONLY);
272 /***************************************************************************/
273 /* ecriture des familles */
275 - toujours creer une famille de numero 0 ne comportant aucun attribut
276 ni groupe (famille de reference pour les noeuds ou les elements
277 qui ne sont rattaches a aucun groupe ni attribut)
278 - les numeros de familles de noeuds sont > 0
279 - les numeros de familles des elements sont < 0
280 - rien d'imposer sur les noms de familles
286 strcpy(nomfam,"FAMILLE_0");
288 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
293 /***************************************************************************/
300 ret = MEDchampCr(fid,champDbleVectNode,MED_REEL64,compDbleVectNode,
301 unitDbleVectNode,mdim);
303 printf("MEDchampCr DbleVectNode : %d \n",ret);
307 ret = MEDchampEcr(fid, maa, champDbleVectNode,
308 (unsigned char *)DbleVectNode,
309 MED_NO_INTERLACE, nnoe,
310 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_NOEUD,
311 0, MED_NOPDT," ", 0., MED_NONOR);
313 printf("MEDchampEcr DbleVectNode : %d \n",ret);
319 ret = MEDchampCr(fid,champDbleVectCell,MED_REEL64,compDbleVectCell,
320 unitDbleVectCell,mdim);
322 printf("MEDchampCr DbleVectCell : %d \n",ret);
326 ret = MEDchampEcr(fid, maa, champDbleVectCell,
327 (unsigned char *)DbleVectCell,
328 MED_NO_INTERLACE, nquad4,
329 MED_NOPG, MED_ALL, MED_NOPFL, WRONLY, MED_MAILLE,
330 MED_QUAD4, MED_NOPDT," ", 0., MED_NONOR);
332 printf("MEDchampEcr DbleVectCell : %d \n",ret);
336 /***************************************************************************/
338 ret = MEDfermer(fid);