ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_ransys.cpp
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
File size: 13315 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 <math.h>
6     #include "m3d_const.h"
7     #include "m3d_hotes.h"
8     #include "m3d_struct.h"
9     #include "m3d_erreur.h"
10     #include "prototype.h"
11     #define MAX_LINE2 81
12     extern int format ;
13     extern GEST_MEM *gest ;
14     extern int nb_max_noe ;
15     extern int debug ;
16     void m3d_ransys(int *nb_noeud,int *nb_ele,float *coord,int *numele,int *ierr)
17     {
18     FILE *stream, *output ;
19     char line[MAX_LINE2] ;
20     char temp[MAX_LINE2] ;
21     char tabel[MAX_LINE2] ;
22     int gtrouve, lg = 16 ;
23     int j,i, num, type, numax, k, lg_line = 0;
24     /* declaration des fonctions */
25     char *ext_noe, *ext_ele ;
26     int *corresp, j1, j2, j3, j4, j5, j6 ;
27     int *old,*neww, *tablin, *numele2, ideb, ifin ;
28     float *coord2, val ;
29    
30     *ierr = FAUX ;
31     *nb_noeud = 0 ;
32     j = 0 ;
33    
34     temp[0] = 0 ;
35     strcpy(temp,gest->buffer) ;
36    
37     k = 0 ;
38     /* ouverture du fichier */
39     if (!(stream = fopen(temp,"r")))
40     {
41     // if (debug) aff_text(" Erreur ouverture du fichier de type ANSYS M3DREC \n") ;
42     *ierr = VRAI ;
43     return ;
44     }
45     /* on se positionne sur le bloc des noeuds */
46     gtrouve = FAUX ;
47     while (gtrouve == FAUX)
48     {
49     if (!fgets(line,MAX_LINE2,stream))
50     {
51     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
52     *ierr = VRAI ;
53     return ;
54     }
55     k++ ;
56     /* lecture des 2 premiers caracteres */
57     tabel[0] = 0 ;
58     strncat(tabel,line,2) ;
59     /* strcmp renvoie la valeur 0 si les 2 chaines sont egales */
60     gtrouve = !strcmp (tabel,"N," ) ;
61     if (!gtrouve) gtrouve = !strcmp (tabel,"n,") ;
62     }
63     *nb_noeud = 1 ;
64     /* on pointe sur la ligne du bloc des noeuds */
65     /* determination du nombre de noeuds et du plus grand numero de noeud */
66     numax = -1 ;
67     while (gtrouve == VRAI)
68     {
69     if (!fgets(line,MAX_LINE2,stream))
70     {
71     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
72     *ierr = VRAI ;
73     return ;
74     }
75     tabel[0] = 0 ;
76     strncat(tabel,line,2) ;/* 2 premiers caracteres */
77     gtrouve = !strcmp (tabel,"n,") ;
78     if (!gtrouve) gtrouve = !strcmp (tabel,"N,") ;
79     if (!gtrouve) break ;
80     (*nb_noeud) = (*nb_noeud) + 1 ;
81     if (*nb_noeud>=nb_max_noe)
82     {
83     // if (debug) aff_text(" Erreur nombre de noeuds M3D_RANSYS \n") ;
84     gest->icode = ERR_NB_NODE ;
85     *ierr = VRAI ;
86     return ;
87     }
88     /* lecture du numero de noeud */
89     tabel[0] = 0 ;
90     strncat(tabel,line+11,7) ;
91     numax = max(numax,atoi(tabel)) ;
92     }
93     /* plus grand numero */
94     gest->numax = numax ;
95     /* alloc du tableau de correspondance */
96     corresp = (int*)calloc(numax+1,sizeof(int)) ;
97     if (corresp == NULL)
98     {
99     // if (debug) aff_text(" Erreur alloc corresp M3DREC \n") ;
100     *ierr = VRAI ;
101     return ;
102     }
103     gest->tabcor = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
104     if (gest->tabcor == NULL)
105     {
106     // if (debug) aff_text(" Erreur alloc M3DREC \n") ;
107     *ierr = VRAI ;
108     return ;
109     }
110     rewind(stream) ;
111     k-- ;
112     for (i=0;i<k;i++)
113     if (!fgets(line,MAX_LINE2,stream))
114     {
115     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
116     *ierr = VRAI ;
117     return ;
118     }
119     /* ******************************************** */
120     /* BLOC DES NOEUDS */
121     /* ******************************************** */
122    
123     for (i=0;i<*nb_noeud;i++)
124     {
125     if (!fgets(line,MAX_LINE2,stream))
126     {
127     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
128     *ierr = VRAI ;
129     return ;
130     }
131     tabel[0] = 0 ;
132     strncat(tabel,line,2) ;/* 2 premiers caracteres */
133     gtrouve = !strcmp (tabel,"N," ) ;
134     if (!gtrouve) gtrouve = !strcmp (tabel,"n,") ;
135     if (gtrouve != VRAI)
136     {
137     // if (debug) aff_text(" Erreur format M3D_RANSYS \n") ;
138     *ierr = VRAI ;
139     return ;
140     }
141    
142     lg_line = strlen(line) ;
143     tabel[0] = 0 ;
144     strncat(tabel,line+11,7) ;
145     num = atoi(tabel) ;
146    
147     val = 0. ;
148     coord[x(i)] = 0. ;
149     coord[y(i)] = 0. ;
150     coord[z(i)] = 0. ;
151    
152     lg = 16 ;
153     if (lg_line > 20)
154     {
155     tabel[0] = 0 ;
156     strncat(tabel,line+19,16) ;
157     m3d_nastof(tabel,&lg,coord+3*i,ierr) ;
158     if (*ierr)
159     {
160     // if (debug) aff_text(" Erreur conversion coordonnees ansys \n") ;
161     return ;
162     }
163     }
164     if (lg_line > 37)
165     {
166     tabel[0] = 0 ;
167     strncat(tabel,line+36,16) ;
168     m3d_nastof(tabel,&lg,coord+(3*i+1),ierr) ;
169     if (*ierr)
170     {
171     // if (debug) aff_text(" Erreur conversion coordonnees ansys \n") ;
172     return ;
173     }
174     }
175     if (lg_line > 54)
176     {
177     tabel[0] = 0 ;
178     strncat(tabel,line+53,16) ;
179     m3d_nastof(tabel,&lg,coord+(3*i+2),ierr) ;
180     if (*ierr)
181     {
182     // if (debug) aff_text(" Erreur conversion coordonnees ansys \n") ;
183     return ;
184     }
185     }
186    
187     /* tables de correspondance anciens nouveaux numeros de noeuds */
188     corresp[num] = i + 1 ;
189     gest->tabcor[i+1] = num ;
190     }
191    
192     /* ******************************************** */
193     /* BLOC DES ELEMENTS */
194     /* ******************************************** */
195    
196     rewind(stream) ;
197    
198     /* on se positionne sur le bloc des elements */
199     gtrouve = FAUX ;
200     j = 0 ;
201     while (gtrouve == FAUX)
202     {
203     if (!fgets(line,MAX_LINE2,stream))
204     {
205     // if (debug) aff_text(" Erreur format du fichier M3D_RANSYS \n") ;
206     *ierr = VRAI ;
207     return ;
208     }
209     tabel[0] = 0 ;
210     strncat(tabel,line,3) ;/* 3 premiers caracteres */
211     gtrouve = !strcmp (tabel,"EN," ) ;
212     if (!gtrouve) gtrouve = !strcmp (tabel,"en," ) ;
213     if (gtrouve != VRAI) j++ ;
214     else
215     {
216     tabel[0] = 0 ;
217     strncat(tabel,line+13,7) ;
218     type = atoi(tabel) ;
219     if (type ==4) gest->is_qua = FAUX ;
220     else if (type ==6) gest->is_qua = VRAI ;
221     else
222     {
223     // if (debug) aff_text(" Erreur format du fichier M3D_RANSYS \n") ;
224     *ierr = VRAI ;
225     return ;
226     }
227     }
228     }
229     /* on pointe en debut de bloc */
230     /* lecture du nombre d'elements */
231     if (!fgets(line,MAX_LINE2,stream))
232     {
233     // if (debug) aff_text(" Erreur format du fichier M3D_RANSYS \n") ;
234     *ierr = VRAI ;
235     return ;
236     }
237     tabel[0] = 0 ;
238     strncat(tabel,line,3) ;/* 3 premiers caracteres */
239     gtrouve = !strcmp (tabel,"EN," ) ;
240     if (!gtrouve) gtrouve = !strcmp (tabel,"en," ) ;
241     if (gtrouve != VRAI)
242     {
243     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
244     *ierr = VRAI ;
245     return ;
246     }
247    
248     tabel[0] = 0 ;
249     strncat(tabel,line+8,4) ;
250     gtrouve = !strcmp (tabel,"NODE" ) ;
251     if (!gtrouve) gtrouve = !strcmp (tabel,"node" ) ;
252     if (gtrouve != VRAI)
253     {
254     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
255     *ierr = VRAI ;
256     return ;
257     }
258     *nb_ele = 1 ;
259     /* determination du nombre d'elements */
260     while (gtrouve == VRAI)
261     {
262     if (!fgets(line,MAX_LINE2,stream))
263     {
264     // if (debug) aff_text(" Erreur format du fichier M3D_RANSYS \n") ;
265     *ierr = VRAI ;
266     return ;
267     }
268     tabel[0] = 0 ;
269     strncat(tabel,line,3) ;/* 3 premiers caracteres */
270     gtrouve = !strcmp (tabel,"EN," ) ;
271     if (!gtrouve) gtrouve = !strcmp (tabel,"en," ) ;
272     if (gtrouve != VRAI) break ;
273     /*
274     tabel[0] = 0 ;
275     strncat(tabel,line+13,7) ;
276     type = atoi(tabel) ;
277     if ((gest->is_qua == FAUX) && ( type =! 4))
278     {
279     if (debug) printf(" Erreur format du fichier M3D_RANSYS \n") ;
280     *ierr = VRAI ;
281     return ;
282     }
283     if ((gest->is_qua == VRAI) && ( type =! 6))
284     {
285     if (debug) printf(" Erreur format du fichier M3D_RANSYS \n") ;
286     *ierr = VRAI ;
287     return ;
288     }
289    
290     if ((type !=6) && (type !=4))
291     {
292     if (debug) printf(" Erreur format du fichier M3D_RANSYS \n") ;
293     *ierr = VRAI ;
294     return ;
295     }
296     */
297     if (!fgets(line,MAX_LINE2,stream))
298     {
299     // if (debug) aff_text(" Erreur format du fichier M3D_RANSYS \n") ;
300     *ierr = VRAI ;
301     return ;
302     }
303     tabel[0] = 0 ;
304     strncat(tabel,line,3) ;
305     gtrouve = !strcmp (tabel,"EN," ) ;
306     if (!gtrouve) gtrouve = !strcmp (tabel,"en," ) ;
307     if (gtrouve != VRAI)
308     {
309     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
310     *ierr = VRAI ;
311     return ;
312     }
313     tabel[0] = 0 ;
314     strncat(tabel,line+8,4) ;
315     gtrouve = !strcmp (tabel,"NODE" ) ;
316     if (!gtrouve) gtrouve = !strcmp (tabel,"node" ) ;
317     if (gtrouve != VRAI)
318     {
319     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
320     *ierr = VRAI ;
321     return ;
322     }
323     (*nb_ele) = (*nb_ele + 1 ) ;
324     }
325     rewind(stream) ;
326     /* on se positionne en tete de bloc des elements */
327     for (i=0;i<j;i++)
328     if (!fgets(line,MAX_LINE2,stream))
329     {
330     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
331     *ierr = VRAI ;
332     return ;
333     }
334     if (gest->is_qua == FAUX) /* lineaire */
335     {
336     for (i=0;i<*nb_ele;i++)
337     {
338     if (!fgets(line,MAX_LINE2,stream))
339     {
340     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
341     *ierr = VRAI ;
342     return ;
343     }
344     if (!fgets(line,MAX_LINE2,stream))
345     {
346     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
347     *ierr = VRAI ;
348     return ;
349     }
350     /* lecture des numeros de noeuds */
351     /* noeud 1 */
352     tabel[0] = 0 ;
353     strncat(tabel,line+13,7) ;
354     numele[3*i] = corresp[atoi(tabel)] ;
355     /* noeud 2 */
356     tabel[0] = 0 ;
357     strncat(tabel,line+21,7) ;
358     numele[3*i+1] = corresp[atoi(tabel)] ;
359     /* noeud 3 */
360     tabel[0] = 0 ;
361     strncat(tabel,line+29,7) ;
362     numele[3*i+2] = corresp[atoi(tabel)] ;
363     tabel[0] = 0 ;
364     strncat(tabel,line+37,7) ;
365     if (numele[3*i+2]!=corresp[atoi(tabel)])
366     {
367     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
368     *ierr = VRAI ;
369     return ;
370     }
371     }
372     }
373     else
374     {
375     /* tableau des coordonnees des noeuds quadratiques,
376     le maillage se fait evidemment en lineaire puis on fait un simple
377     post-traitement */
378    
379     /* lecture des noeuds ->on remplit coord2 */
380     gest->coord2 = (float*)calloc(3*(*nb_noeud),sizeof(float)) ;
381     if (gest->coord2 == NULL)
382     {
383     // if (debug) aff_text(" Erreur alloc coord2 M3DREC \n") ;
384     *ierr = VRAI ;
385     return ;
386     }
387     coord2 = gest->coord2 ;
388     /* si tablin[i] = VRAI le noeud est un noeud du maillage (sommet de triangle) */
389     gest->tablin = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
390     /* les noeuds sont ils des noeuds du maillage */
391     if (gest->tablin == NULL)
392     {
393     // if (debug) aff_text(" Erreur alloc tablin M3DREC \n") ;
394     *ierr = VRAI ;
395     return ;
396     }
397     tablin = gest->tablin ;
398     for (i=0;i<=*nb_noeud;i++) tablin[i] = VRAI ;
399     gest->neww = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
400     if (gest->neww == NULL)
401     {
402     // if (debug) aff_text(" Erreur alloc new M3DREC \n") ;
403     *ierr = VRAI ;
404     return ;
405     }
406     neww = gest->neww ;
407     gest->old = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
408     if (gest->old == NULL)
409     {
410     // if (debug) aff_text(" Erreur alloc old M3DREC \n") ;
411     *ierr = VRAI ;
412     return ;
413     }
414     old = gest->old ;
415     gest->nb_noe_qua = *nb_noeud ;
416     /* transfert */
417     for (i=0;i<3 *(*nb_noeud);i++) coord2[i] = coord[i] ;
418    
419     /* on a rempli le tableau des noeuds quadratiques */
420     /* parcours des elements gestions des noeuds quadratiques */
421     /* reperer les numeros de noeuds quadratiques */
422    
423     gest->numele2 = (int*)calloc(6 * (*nb_ele),sizeof(int)) ;
424     if (gest->numele2 == NULL)
425     {
426     // if (debug) aff_text(" Erreur alloc numele2 M3DREC \n") ;
427     *ierr = VRAI ;
428     return ;
429     }
430     numele2 = gest->numele2 ;
431    
432     /* numele2 contient le maillage quadratique de la peau */
433     for (i=0;i<*nb_ele;i++)
434     {
435     if (!fgets(line,MAX_LINE2,stream))
436     {
437     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
438     *ierr = VRAI ;
439     return ;
440     }
441     if (!fgets(line,MAX_LINE2,stream))
442     {
443     // if (debug) aff_text(" Erreur format du fichier M3DREC \n") ;
444     *ierr = VRAI ;
445     return ;
446     }
447     /* les 3 premiers noeuds sont des sommets != systus et mosaic */
448     /* lecture des numeros de noeuds */
449     /* noeud 1 */
450     tabel[0] = 0 ;
451     strncat(tabel,line+13,7) ;
452     numele[3*i] = corresp[atoi(tabel)] ;
453     numele2[6*i] = numele[3*i] ;
454    
455     /* noeud 2 */
456     tabel[0] = 0 ;
457     strncat(tabel,line+21,7) ;
458     numele[3*i+1] = corresp[atoi(tabel)] ;
459     numele2[6*i+2] = numele[3*i+1] ;
460    
461     /* noeud 3 */
462     tabel[0] = 0 ;
463     strncat(tabel,line+29,7) ;
464     numele[3*i+2] = corresp[atoi(tabel)] ;
465     numele2[6*i+4] = numele[3*i+2] ;
466    
467     /* noeud 4 = noeud milieu d'arete */
468     tabel[0] = 0 ;
469     strncat(tabel,line+45,7) ;
470     numele2[6*i+1] = corresp[atoi(tabel)] ;
471     tablin[corresp[atoi(tabel)]] = FAUX ;
472    
473     /* noeud 5 = noeud milieu d'arete */
474     tabel[0] = 0 ;
475     strncat(tabel,line+53,7) ;
476     numele2[6*i+3] = corresp[atoi(tabel)] ;
477     tablin[corresp[atoi(tabel)]] = FAUX ;
478    
479     /* noeud 6 = noeud milieu d'arete */
480     tabel[0] = 0 ;
481     strncat(tabel,line+69,7) ;
482     numele2[6*i+5] = corresp[atoi(tabel)] ;
483     tablin[corresp[atoi(tabel)]] = FAUX ;
484     }
485    
486     /* parcours du tableau des coordonnees coord2 */
487     *nb_noeud = 0 ;
488     for (i=1;i<=gest->nb_noe_qua;i++)/* numeros fortran */
489     {
490     if (tablin[i]==VRAI)
491     {
492     coord[x(*nb_noeud)] = coord2[x(i-1)] ;
493     coord[y(*nb_noeud)] = coord2[y(i-1)] ;
494     coord[z(*nb_noeud)] = coord2[z(i-1)] ;
495     *nb_noeud = *nb_noeud + 1 ;
496     /* correspondance */
497     neww[i] = *nb_noeud ;
498     old[*nb_noeud] = i ;
499     }
500     }
501     /* renumerotation des elements */
502     for (i=0;i<*nb_ele;i++)/* numeros fortran */
503     {
504     numele[3*i] = neww[numele[3*i]] ;
505     numele[3*i+1] = neww[numele[3*i+1]] ;
506     numele[3*i+2] = neww[numele[3*i+2]] ;
507     }
508     }
509     fclose(stream) ;
510     free(corresp) ;
511     return ;
512     }
513    
514    
515