ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_rnastran.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 14862 byte(s)
Log Message:
structure de l'écriture

File Contents

# User Rev Content
1 francois 283
2     #include <stdio.h>
3     #include <string.h>
4     #include <stdlib.h>
5     #include "m3d_const.h"
6     #include "m3d_hotes.h"
7     #include "m3d_struct.h"
8     #include "m3d_erreur.h"
9     #include "prototype.h"
10     extern int format ;
11     extern GEST_MEM *gest ;
12     extern int nb_max_noe ;
13     void m3d_rnastran(int *nb_noeud,int *nb_ele,float *coord,int *numele,int *ierr)
14     {
15     FILE *stream ;
16     char line[MAX_LINE] ;
17     char temp[MAX_LINE] ;
18     char tabel[MAX_LINE] ;
19     char tabel2[MAX_LINE] ;
20     int gtrouve, is_large, lg ;
21     int j,i, type;
22     /* declaration des fonctions */
23     char *ext_ele ;
24     int *corresp, itype ;
25     int *old, *neww, *tablin, *numele2;
26     float *coord2 ;
27    
28     *ierr = FAUX ;
29     *nb_noeud = 0 ;
30     *nb_ele = 0 ;
31     itype = 0 ;
32     j = 0 ;
33     gest->numax = -1 ;
34    
35     /* extension du fichier */
36     /*
37     ext_ele = EXT_ELE_NASTRAN ;
38     */
39     /* le nom du fichier contient l'extension */
40     temp[0] = 0 ;
41     strcpy(temp,gest->buffer) ;
42     /*
43     strncat(temp,ext_ele,4) ;
44     */
45    
46     /* ouverture du fichier */
47     if (!(stream = fopen(temp,"r")))
48     {
49     m3d_erreur(ERR_OPEN) ;
50     *ierr = VRAI ;
51     return ;
52     }
53     while (fgets(line,MAX_LINE,stream)) /* tant que le fichier n'est pas vide */
54     {
55     tabel[0] = 0 ;
56     strncat(tabel,line,5) ;
57     if (!strcmp (tabel,"GRID " ))
58     {
59     (*nb_noeud) = (*nb_noeud + 1 ) ;
60     if (*nb_noeud>=nb_max_noe)
61     {
62     m3d_erreur(ERR_NB_NOE) ;
63     *ierr = VRAI ;
64     return ;
65     }
66     tabel[0] = 0 ;
67     /* plus grand numero de noeud */
68     strncat(tabel,line+8,8) ;/* 8 caracteres */
69     gest->numax = max(gest->numax,atoi(tabel)) ;
70     }
71     if (!strcmp (tabel,"GRID*" ))
72     {
73     (*nb_noeud) = (*nb_noeud + 1 ) ;
74     if (*nb_noeud>=nb_max_noe)
75     {
76     m3d_erreur(ERR_NB_NOE) ;
77     *ierr = VRAI ;
78     return ;
79     }
80     tabel[0] = 0 ;
81     /* plus grand numero de noeud */
82     strncat(tabel,line+8,16) ;/* 16 caracteres */
83     gest->numax = max(gest->numax,atoi(tabel)) ;
84     }
85     }
86     /* plus grand numero */
87     /* alloc du tableau de correspondance */
88     corresp = (int*)calloc(gest->numax+1,sizeof(int)) ;
89     if (corresp == NULL)
90     {
91     m3d_erreur(ERR_ALLOC) ;
92     *ierr = VRAI ;
93     return ;
94     }
95     gest->tabcor = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
96     if (gest->tabcor == NULL)
97     {
98     m3d_erreur(ERR_ALLOC) ;
99     *ierr = VRAI ;
100     return ;
101     }
102     rewind(stream) ;
103    
104     /* ******************************************** */
105     /* BLOC DES NOEUDS */
106     /* ******************************************** */
107    
108     i = 0 ;
109     while (fgets(line,MAX_LINE,stream)) /* tant que le fichier n'est pas vide */
110     {
111     tabel[0] = 0 ;
112     strncat(tabel,line,5) ;/* 5 premiers caracteres */
113     if (!strcmp (tabel,"GRID "))
114     {
115     if (sscanf(line,"%8s%8d",tabel,&j)!=2)
116     {
117     m3d_erreur(ERR_FORMAT) ;
118     *ierr = VRAI ;
119     return ;
120     }
121     lg = 8 ;
122     tabel[0] = 0 ;
123     strncat(tabel,line+24,8) ;
124     m3d_nastof(tabel,&lg,coord+3*i,ierr) ;
125     if (*ierr)
126     {
127     m3d_erreur(ERR_FORMAT) ;
128     return ;
129     }
130     tabel[0] = 0 ;
131     strncat(tabel,line+32,8) ;
132     m3d_nastof(tabel,&lg,coord+(3*i+1),ierr) ;
133     if (*ierr)
134     {
135     m3d_erreur(ERR_FORMAT) ;
136     return ;
137     }
138     tabel[0] = 0 ;
139     strncat(tabel,line+40,8) ;
140     m3d_nastof(tabel,&lg,coord+(3*i+2),ierr) ;
141     if (*ierr)
142     {
143     m3d_erreur(ERR_FORMAT) ;
144     return ;
145     }
146     /* tables de correspondance anciens nouveaux numeros de noeuds */
147     corresp[j] = i + 1 ;
148     gest->tabcor[i+1] = j ;
149     i++ ;
150     }
151     if (!strcmp (tabel,"GRID*" ))
152     {
153     if (sscanf(line,"%8s%16d",tabel,&j)!=2)
154     {
155     m3d_erreur(ERR_FORMAT) ;
156     *ierr = VRAI ;
157     return ;
158     }
159     lg = 16 ;
160     tabel[0] = 0 ;
161     strncat(tabel,line+40,16) ;
162     m3d_nastof(tabel,&lg,coord+3*i,ierr) ;
163     if (*ierr)
164     {
165     m3d_erreur(ERR_FORMAT) ;
166     return ;
167     }
168     tabel[0] = 0 ;
169     strncat(tabel,line+56,16) ;
170     m3d_nastof(tabel,&lg,coord+(3*i+1),ierr) ;
171     if (*ierr)
172     {
173     m3d_erreur(ERR_FORMAT) ;
174     return ;
175     }
176     /* passer a la ligne suivante */
177     if (!fgets(line,MAX_LINE,stream))
178     {
179     m3d_erreur(ERR_FORMAT) ;
180     *ierr = VRAI ;
181     return ;
182     }
183     tabel[0] = 0 ;
184     strncat(tabel,line+8,16) ;
185     m3d_nastof(tabel,&lg,coord+(3*i+2),ierr) ;
186     if (*ierr)
187     {
188     m3d_erreur(ERR_FORMAT) ;
189     return ;
190     }
191     /* tables de correspondance anciens nouveaux numeros de noeuds */
192     corresp[j] = i + 1 ;
193     gest->tabcor[i+1] = j ;
194     i++ ;
195     }
196     }
197     rewind(stream) ;
198    
199     /* ******************************************** */
200     /* BLOC DES ELEMENTS */
201     /* ******************************************** */
202    
203     while (fgets(line,MAX_LINE,stream))
204     {
205     tabel[0] = 0 ;
206     strncat(tabel,line,5) ;/* 5 premiers caracteres */
207     gtrouve = !strcmp (tabel,"CTRIA" ) ;
208    
209     if (gtrouve)
210     {
211     /* test si maillage lineaire ou quadratique */
212     tabel[0] = 0 ;
213     strncat(tabel,line+5,1) ;/* lecture du sixieme caractere */
214     type = atoi(tabel) ;
215     switch (type)
216     {
217     case 1 :
218     case 2 :
219     case 3 : /* CTRIA1 , CTRIA2, CTRIA3 : lineaire */
220     gest->is_qua = FAUX ;
221     break ;
222     case 6 :
223     gest->is_qua = VRAI ;/* CTRIA6 */
224     break ;
225     default :
226     m3d_erreur(ERR_TYPE_ELE) ;
227     *ierr = VRAI ;
228     return ;
229     }
230     (*nb_ele) = (*nb_ele) + 1 ;
231     }
232     }
233     if (*nb_ele == 0)
234     {
235     m3d_erreur(ERR_FORMAT);
236     *ierr = VRAI ;
237     return ;
238     }
239    
240     rewind(stream) ;
241     /* mailles lineaires */
242     i = 0 ;
243     if (gest->is_qua == FAUX)
244     {
245     while (fgets(line,MAX_LINE,stream))
246     {
247     tabel[0] = 0 ;
248     strncat(tabel,line,5) ;
249     if (!strcmp (tabel,"CTRIA"))
250     {
251     tabel[0] = 0 ;
252     strncat(tabel,line+6,1) ;
253     if (!strcmp (tabel," "))
254     {
255     tabel[0] = 0 ;
256     strncat(tabel,line+24,8) ;
257     numele[3*i] = corresp[atoi(tabel)] ;
258     tabel[0] = 0 ;
259     strncat(tabel,line+32,8) ;
260     numele[3*i+1] = corresp[atoi(tabel)] ;
261     tabel[0] = 0 ;
262     strncat(tabel,line+40,8) ;
263     numele[3*i+2] = corresp[atoi(tabel)] ;
264     i++ ;
265     }
266     if (!strcmp (tabel,"*" ))/* large */
267     {
268     tabel[0] = 0 ;
269     strncat(tabel,line+40,16) ;
270     numele[3*i] = corresp[atoi(tabel)] ;
271     tabel[0] = 0 ;
272     strncat(tabel,line+56,16) ;
273     numele[3*i+1] = corresp[atoi(tabel)] ;
274     /* passer a la ligne suivante */
275     if (!fgets(line,MAX_LINE,stream))
276     {
277     m3d_erreur(ERR_FORMAT);
278     *ierr = VRAI ;
279     return ;
280     }
281     tabel[0] = 0 ;
282     strncat(tabel,line+8,16) ;
283     numele[3*i+2] = corresp[atoi(tabel)] ;
284     i++ ;
285     }
286     }
287     }
288     }
289     else /* mailles quadratiques */
290     {
291     /* tableau des coordonnees des noeuds quadratiques,
292     le maillage se fait evidemment en lineaire puis on fait un simple
293     post-traitement */
294    
295     /* lecture des noeuds ->on remplit coord2 */
296     gest->coord2 = (float*)calloc(3*(*nb_noeud),sizeof(float)) ;
297     if (gest->coord2 == NULL)
298     {
299     m3d_erreur(ERR_ALLOC) ;
300     *ierr = VRAI ;
301     return ;
302     }
303     coord2 = gest->coord2 ;
304     /* si tablin[i] = VRAI le noeud est un noeud du maillage (sommet de triangle) */
305     gest->tablin = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
306     /* les noeuds sont ils des noeuds du maillage */
307     if (gest->tablin == NULL)
308     {
309     m3d_erreur(ERR_ALLOC) ;
310     *ierr = VRAI ;
311     return ;
312     }
313     tablin = gest->tablin ;
314     for (i=0;i<=*nb_noeud;i++) tablin[i] = VRAI ;
315     gest->neww = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
316     if (gest->neww == NULL)
317     {
318     m3d_erreur(ERR_ALLOC) ;
319     *ierr = VRAI ;
320     return ;
321     }
322     neww = gest->neww ;
323     gest->old = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
324     if (gest->old == NULL)
325     {
326     m3d_erreur(ERR_ALLOC) ;
327     *ierr = VRAI ;
328     return ;
329     }
330     old = gest->old ;
331     gest->nb_noe_qua = *nb_noeud ;
332     /* transfert */
333     for (i=0;i<3 *(*nb_noeud);i++) coord2[i] = coord[i] ;
334    
335     /* on a rempli le tableau des noeuds quadratiques */
336     /* parcours des elements gestions des noeuds quadratiques */
337     /* reperer les numeros de noeuds quadratiques */
338    
339     gest->numele2 = (int*)calloc(6 * (*nb_ele),sizeof(int)) ;
340     if (gest->numele2 == NULL)
341     {
342     m3d_erreur(ERR_ALLOC) ;
343     *ierr = VRAI ;
344     return ;
345     }
346     numele2 = gest->numele2 ;
347     /* numele2 contient le maillage quadratique de la peau */
348     i = 0 ;
349     while (fgets(line,MAX_LINE,stream))
350     {
351     tabel[0] = 0 ;
352     strncat(tabel,line,5) ;
353     if (!strcmp (tabel,"CTRIA"))
354     {
355     tabel[0] = 0 ;
356     strncat(tabel,line+6,1) ;
357     if (!strcmp (tabel," "))/* small */
358     {
359     /* noeud 1 */
360     tabel[0] = 0 ;
361     strncat(tabel,line+24,8) ;
362     numele[3*i] = corresp[atoi(tabel)] ;
363     numele2[6*i] = numele[3*i] ;
364    
365     /* noeud 2 */
366     tabel[0] = 0 ;
367     strncat(tabel,line+32,8) ;
368     numele[3*i+1] = corresp[atoi(tabel)] ;
369     numele2[6*i+2] = numele[3*i+1] ;
370    
371     /* noeud 3 */
372     tabel[0] = 0 ;
373     strncat(tabel,line+40,8) ;
374     numele[3*i+2] = corresp[atoi(tabel)] ;
375     numele2[6*i+4] = numele[3*i+2] ;
376    
377     /* noeud 4 = noeud milieu d'arete */
378     tabel[0] = 0 ;
379     strncat(tabel,line+48,8) ;
380     numele2[6*i+1] = corresp[atoi(tabel)] ;
381     tablin[corresp[atoi(tabel)]] = FAUX ;
382    
383     /* noeud 5 = noeud milieu d'arete */
384     tabel[0] = 0 ;
385     strncat(tabel,line+56,8) ;
386     numele2[6*i+3] = corresp[atoi(tabel)] ;
387     tablin[corresp[atoi(tabel)]] = FAUX ;
388    
389     /* noeud 6 = noeud milieu d'arete */
390     tabel[0] = 0 ;
391     strncat(tabel,line+64,8) ;
392     numele2[6*i+5] = corresp[atoi(tabel)] ;
393     tablin[corresp[atoi(tabel)]] = FAUX ;
394     i++ ;
395     }
396     if (!strcmp (tabel,"*" ))/* large */
397     {
398     /* noeud 1 */
399     tabel[0] = 0 ;
400     strncat(tabel,line+40,16) ;
401     numele[3*i] = corresp[atoi(tabel)] ;
402     numele2[6*i] = numele[3*i] ;
403    
404     /* noeud 2 */
405     tabel[0] = 0 ;
406     strncat(tabel,line+56,16) ;
407     numele[3*i+1] = corresp[atoi(tabel)] ;
408     numele2[6*i+2] = numele[3*i+1] ;
409    
410     /* passer a la ligne suivante */
411     if (!fgets(line,MAX_LINE,stream))
412     {
413     m3d_erreur(ERR_FORMAT) ;
414     *ierr = VRAI ;
415     return ;
416     }
417     /* noeud 3 */
418     tabel[0] = 0 ;
419     strncat(tabel,line+8,16) ;
420     numele[3*i+2] = corresp[atoi(tabel)] ;
421     numele2[6*i+4] = numele[3*i+2] ;
422    
423     /* noeud 4 = noeud milieu d'arete */
424     tabel[0] = 0 ;
425     strncat(tabel,line+24,16) ;
426     numele2[6*i+1] = corresp[atoi(tabel)] ;
427     tablin[corresp[atoi(tabel)]] = FAUX ;
428    
429     /* noeud 5 = noeud milieu d'arete */
430     tabel[0] = 0 ;
431     strncat(tabel,line+40,16) ;
432     numele2[6*i+3] = corresp[atoi(tabel)] ;
433     tablin[corresp[atoi(tabel)]] = FAUX ;
434    
435     /* noeud 6 = noeud milieu d'arete */
436     tabel[0] = 0 ;
437     strncat(tabel,line+56,16) ;
438     numele2[6*i+5] = corresp[atoi(tabel)] ;
439     tablin[corresp[atoi(tabel)]] = FAUX ;
440     i++ ;
441     }
442     }
443     }
444    
445     /* parcours du tableau des coordonnees coord2 */
446     *nb_noeud = 0 ;
447     for (i=1;i<=gest->nb_noe_qua;i++)/* numeros fortran */
448     {
449     if (tablin[i]==VRAI)
450     {
451     coord[x(*nb_noeud)] = coord2[x(i-1)] ;
452     coord[y(*nb_noeud)] = coord2[y(i-1)] ;
453     coord[z(*nb_noeud)] = coord2[z(i-1)] ;
454     *nb_noeud = *nb_noeud + 1 ;
455     /* correspondance */
456     neww[i] = *nb_noeud ;
457     old[*nb_noeud] = i ;
458     }
459     }
460     /* renumerotation des elements */
461     for (i=0;i<*nb_ele;i++)/* numeros fortran */
462     {
463     numele[3*i] = neww[numele[3*i]] ;
464     numele[3*i+1] = neww[numele[3*i+1]] ;
465     numele[3*i+2] = neww[numele[3*i+2]] ;
466     }
467     }
468     fclose(stream) ;
469     free(corresp) ;
470     return ;
471     }
472    
473    
474