ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_rnastran.cpp
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
File size: 11602 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

# User Rev Content
1 5
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 : case 2 : case 3 : /* CTRIA1 , CTRIA2, CTRIA3 : lineaire */
218     gest->is_qua = FAUX ;
219     break ;
220     case 6 :
221     gest->is_qua = VRAI ;/* CTRIA6 */
222     break ;
223     default :
224     m3d_erreur(ERR_TYPE_ELE) ;
225     *ierr = VRAI ;
226     return ;
227     }
228     (*nb_ele) = (*nb_ele) + 1 ;
229     }
230     }
231     if (*nb_ele == 0)
232     {
233     m3d_erreur(ERR_FORMAT);
234     *ierr = VRAI ;
235     return ;
236     }
237    
238     rewind(stream) ;
239     /* mailles lineaires */
240     i = 0 ;
241     if (gest->is_qua == FAUX)
242     {
243     while (fgets(line,MAX_LINE,stream))
244     {
245     tabel[0] = 0 ;
246     strncat(tabel,line,5) ;
247     if (!strcmp (tabel,"CTRIA"))
248     {
249     tabel[0] = 0 ;
250     strncat(tabel,line+6,1) ;
251     if (!strcmp (tabel," "))
252     {
253     tabel[0] = 0 ;
254     strncat(tabel,line+24,8) ;
255     numele[3*i] = corresp[atoi(tabel)] ;
256     tabel[0] = 0 ;
257     strncat(tabel,line+32,8) ;
258     numele[3*i+1] = corresp[atoi(tabel)] ;
259     tabel[0] = 0 ;
260     strncat(tabel,line+40,8) ;
261     numele[3*i+2] = corresp[atoi(tabel)] ;
262     i++ ;
263     }
264     if (!strcmp (tabel,"*" ))/* large */
265     {
266     tabel[0] = 0 ;
267     strncat(tabel,line+40,16) ;
268     numele[3*i] = corresp[atoi(tabel)] ;
269     tabel[0] = 0 ;
270     strncat(tabel,line+56,16) ;
271     numele[3*i+1] = corresp[atoi(tabel)] ;
272     /* passer a la ligne suivante */
273     if (!fgets(line,MAX_LINE,stream))
274     {
275     m3d_erreur(ERR_FORMAT);
276     *ierr = VRAI ;
277     return ;
278     }
279     tabel[0] = 0 ;
280     strncat(tabel,line+8,16) ;
281     numele[3*i+2] = corresp[atoi(tabel)] ;
282     i++ ;
283     }
284     }
285     }
286     }
287     else /* mailles quadratiques */
288     {
289     /* tableau des coordonnees des noeuds quadratiques,
290     le maillage se fait evidemment en lineaire puis on fait un simple
291     post-traitement */
292    
293     /* lecture des noeuds ->on remplit coord2 */
294     gest->coord2 = (float*)calloc(3*(*nb_noeud),sizeof(float)) ;
295     if (gest->coord2 == NULL)
296     {
297     m3d_erreur(ERR_ALLOC) ;
298     *ierr = VRAI ;
299     return ;
300     }
301     coord2 = gest->coord2 ;
302     /* si tablin[i] = VRAI le noeud est un noeud du maillage (sommet de triangle) */
303     gest->tablin = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
304     /* les noeuds sont ils des noeuds du maillage */
305     if (gest->tablin == NULL)
306     {
307     m3d_erreur(ERR_ALLOC) ;
308     *ierr = VRAI ;
309     return ;
310     }
311     tablin = gest->tablin ;
312     for (i=0;i<=*nb_noeud;i++) tablin[i] = VRAI ;
313     gest->neww = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
314     if (gest->neww == NULL)
315     {
316     m3d_erreur(ERR_ALLOC) ;
317     *ierr = VRAI ;
318     return ;
319     }
320     neww = gest->neww ;
321     gest->old = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
322     if (gest->old == NULL)
323     {
324     m3d_erreur(ERR_ALLOC) ;
325     *ierr = VRAI ;
326     return ;
327     }
328     old = gest->old ;
329     gest->nb_noe_qua = *nb_noeud ;
330     /* transfert */
331     for (i=0;i<3 *(*nb_noeud);i++) coord2[i] = coord[i] ;
332    
333     /* on a rempli le tableau des noeuds quadratiques */
334     /* parcours des elements gestions des noeuds quadratiques */
335     /* reperer les numeros de noeuds quadratiques */
336    
337     gest->numele2 = (int*)calloc(6 * (*nb_ele),sizeof(int)) ;
338     if (gest->numele2 == NULL)
339     {
340     m3d_erreur(ERR_ALLOC) ;
341     *ierr = VRAI ;
342     return ;
343     }
344     numele2 = gest->numele2 ;
345     /* numele2 contient le maillage quadratique de la peau */
346     i = 0 ;
347     while (fgets(line,MAX_LINE,stream))
348     {
349     tabel[0] = 0 ;
350     strncat(tabel,line,5) ;
351     if (!strcmp (tabel,"CTRIA"))
352     {
353     tabel[0] = 0 ;
354     strncat(tabel,line+6,1) ;
355     if (!strcmp (tabel," "))/* small */
356     {
357     /* noeud 1 */
358     tabel[0] = 0 ;
359     strncat(tabel,line+24,8) ;
360     numele[3*i] = corresp[atoi(tabel)] ;
361     numele2[6*i] = numele[3*i] ;
362    
363     /* noeud 2 */
364     tabel[0] = 0 ;
365     strncat(tabel,line+32,8) ;
366     numele[3*i+1] = corresp[atoi(tabel)] ;
367     numele2[6*i+2] = numele[3*i+1] ;
368    
369     /* noeud 3 */
370     tabel[0] = 0 ;
371     strncat(tabel,line+40,8) ;
372     numele[3*i+2] = corresp[atoi(tabel)] ;
373     numele2[6*i+4] = numele[3*i+2] ;
374    
375     /* noeud 4 = noeud milieu d'arete */
376     tabel[0] = 0 ;
377     strncat(tabel,line+48,8) ;
378     numele2[6*i+1] = corresp[atoi(tabel)] ;
379     tablin[corresp[atoi(tabel)]] = FAUX ;
380    
381     /* noeud 5 = noeud milieu d'arete */
382     tabel[0] = 0 ;
383     strncat(tabel,line+56,8) ;
384     numele2[6*i+3] = corresp[atoi(tabel)] ;
385     tablin[corresp[atoi(tabel)]] = FAUX ;
386    
387     /* noeud 6 = noeud milieu d'arete */
388     tabel[0] = 0 ;
389     strncat(tabel,line+64,8) ;
390     numele2[6*i+5] = corresp[atoi(tabel)] ;
391     tablin[corresp[atoi(tabel)]] = FAUX ;
392     i++ ;
393     }
394     if (!strcmp (tabel,"*" ))/* large */
395     {
396     /* noeud 1 */
397     tabel[0] = 0 ;
398     strncat(tabel,line+40,16) ;
399     numele[3*i] = corresp[atoi(tabel)] ;
400     numele2[6*i] = numele[3*i] ;
401    
402     /* noeud 2 */
403     tabel[0] = 0 ;
404     strncat(tabel,line+56,16) ;
405     numele[3*i+1] = corresp[atoi(tabel)] ;
406     numele2[6*i+2] = numele[3*i+1] ;
407    
408     /* passer a la ligne suivante */
409     if (!fgets(line,MAX_LINE,stream))
410     {
411     m3d_erreur(ERR_FORMAT) ;
412     *ierr = VRAI ;
413     return ;
414     }
415     /* noeud 3 */
416     tabel[0] = 0 ;
417     strncat(tabel,line+8,16) ;
418     numele[3*i+2] = corresp[atoi(tabel)] ;
419     numele2[6*i+4] = numele[3*i+2] ;
420    
421     /* noeud 4 = noeud milieu d'arete */
422     tabel[0] = 0 ;
423     strncat(tabel,line+24,16) ;
424     numele2[6*i+1] = corresp[atoi(tabel)] ;
425     tablin[corresp[atoi(tabel)]] = FAUX ;
426    
427     /* noeud 5 = noeud milieu d'arete */
428     tabel[0] = 0 ;
429     strncat(tabel,line+40,16) ;
430     numele2[6*i+3] = corresp[atoi(tabel)] ;
431     tablin[corresp[atoi(tabel)]] = FAUX ;
432    
433     /* noeud 6 = noeud milieu d'arete */
434     tabel[0] = 0 ;
435     strncat(tabel,line+56,16) ;
436     numele2[6*i+5] = corresp[atoi(tabel)] ;
437     tablin[corresp[atoi(tabel)]] = FAUX ;
438     i++ ;
439     }
440     }
441     }
442    
443     /* parcours du tableau des coordonnees coord2 */
444     *nb_noeud = 0 ;
445     for (i=1;i<=gest->nb_noe_qua;i++)/* numeros fortran */
446     {
447     if (tablin[i]==VRAI)
448     {
449     coord[x(*nb_noeud)] = coord2[x(i-1)] ;
450     coord[y(*nb_noeud)] = coord2[y(i-1)] ;
451     coord[z(*nb_noeud)] = coord2[z(i-1)] ;
452     *nb_noeud = *nb_noeud + 1 ;
453     /* correspondance */
454     neww[i] = *nb_noeud ;
455     old[*nb_noeud] = i ;
456     }
457     }
458     /* renumerotation des elements */
459     for (i=0;i<*nb_ele;i++)/* numeros fortran */
460     {
461     numele[3*i] = neww[numele[3*i]] ;
462     numele[3*i+1] = neww[numele[3*i+1]] ;
463     numele[3*i+2] = neww[numele[3*i+2]] ;
464     }
465     }
466     fclose(stream) ;
467     free(corresp) ;
468     return ;
469     }
470    
471    
472