1 // GetDP - Copyright (C) 1997-2021 P. Dular and C. Geuzaine, University of Liege
2 //
3 // See the LICENSE.txt file for license information. Please report all
4 // issues on https://gitlab.onelab.info/getdp/getdp/issues.
5 
6 #include <string.h>
7 #include "GeoData.h"
8 #include "ProData.h"
9 #include "GeoEntity.h"
10 #include "MallocUtils.h"
11 #include "Message.h"
12 
13 extern FILE            * File_PRE ;
14 extern struct GeoData  * CurrentGeoData ;
15 extern int               Flag_XDATA ;
16 
17 /* ------------------------------------------------------------------------ */
18 /*  G e o _ G e t N o d e s _ u v w                                         */
19 /* ------------------------------------------------------------------------ */
20 
Geo_GetNodes_uvw(int Type,int * nbn)21 double * Geo_GetNodes_uvw(int Type, int *nbn)
22 {
23   switch(Type){
24   case POINT_ELEMENT : *nbn = NbrNodes_Point ;     return(*Nodes_Point) ;
25 
26   case LINE        : *nbn = NbrNodes_Line ;        return(*Nodes_Line) ;
27   case TRIANGLE    : *nbn = NbrNodes_Triangle ;    return(*Nodes_Triangle) ;
28   case QUADRANGLE  : *nbn = NbrNodes_Quadrangle ;  return(*Nodes_Quadrangle) ;
29   case TETRAHEDRON : *nbn = NbrNodes_Tetrahedron ; return(*Nodes_Tetrahedron) ;
30   case HEXAHEDRON  : *nbn = NbrNodes_Hexahedron ;  return(*Nodes_Hexahedron) ;
31   case PRISM       : *nbn = NbrNodes_Prism ;       return(*Nodes_Prism) ;
32   case PYRAMID     : *nbn = NbrNodes_Pyramid ;     return(*Nodes_Pyramid) ;
33 
34   case LINE_2      : *nbn = NbrNodes_Line_2 ;      return(*Nodes_Line_2) ;
35   case TRIANGLE_2  : *nbn = NbrNodes_Triangle_2 ;  return(*Nodes_Triangle_2) ;
36   case QUADRANGLE_2: *nbn = NbrNodes_Quadrangle_2 ;return(*Nodes_Quadrangle_2) ;
37   case QUADRANGLE_2_8N: *nbn = NbrNodes_Quadrangle_2_8N ;return(*Nodes_Quadrangle_2_8N);
38   case TETRAHEDRON_2: *nbn = NbrNodes_Tetrahedron_2; return(*Nodes_Tetrahedron_2) ;
39 
40   default :
41     Message::Error("Unknown type of Element in Geo_GetNodes_uvw") ; return(NULL) ;
42   }
43 }
44 
45 /* ------------------------------------------------------------------------ */
46 /*  G e o _ C r e a t e E d g e s O f E l e m e n t                         */
47 /* ------------------------------------------------------------------------ */
48 
Geo_CreateEdgesOfElement(struct Geo_Element * Geo_Element)49 void Geo_CreateEdgesOfElement(struct Geo_Element * Geo_Element)
50 {
51   int  Nbr_Entities2, * D_Element ;
52 
53   D_Element = Geo_GetIM_Den(Geo_Element->Type, &Nbr_Entities2) ;
54   if(!Nbr_Entities2) return;
55   Geo_CreateEntitiesOfElement(Nbr_Entities2, D_Element,
56 			      Geo_Element->NbrNodes, Geo_Element->NumNodes,
57 			      &Geo_Element->NbrEdges, &Geo_Element->NumEdges,
58 			      &CurrentGeoData->NbrElementsWithEdges,
59 			      &CurrentGeoData->NumCurrentEdge,
60 			      CurrentGeoData->EdgesXNodes) ;
61 }
62 
63 /* ------------------------------------------------------------------------ */
64 /*  G e o _ G e t N o d e s O f E d g e I n E l e m e n t                   */
65 /* ------------------------------------------------------------------------ */
66 
Geo_GetNodesOfEdgeInElement(struct Geo_Element * Geo_Element,int Num_Edge)67 int *Geo_GetNodesOfEdgeInElement(struct Geo_Element * Geo_Element, int Num_Edge)
68 {
69   int  Nbr_Entities2 ;
70 
71   return( Geo_GetIM_Den(Geo_Element->Type, &Nbr_Entities2) +
72 		Num_Edge * NBR_MAX_SUBENTITIES_IN_ELEMENT ) ;
73 }
74 
75 /* ------------------------------------------------------------------------ */
76 /*  G e o _ G e t N o d e s O f F a c e t I n E l e m e n t                 */
77 /* ------------------------------------------------------------------------ */
78 
Geo_GetNodesOfFacetInElement(struct Geo_Element * Geo_Element,int Num_Facet)79 int *Geo_GetNodesOfFacetInElement(struct Geo_Element * Geo_Element, int Num_Facet)
80 {
81   int  Nbr_Entities2 ;
82 
83   return( Geo_GetIM_Dfn(Geo_Element->Type, &Nbr_Entities2) +
84 		Num_Facet * NBR_MAX_SUBENTITIES_IN_ELEMENT ) ;
85 }
86 
87 /* ------------------------------------------------------------------------ */
88 /*  G e o _ C r e a t e F a c e t s O f E l e m e n t                       */
89 /* ------------------------------------------------------------------------ */
90 
Geo_CreateFacetsOfElement(struct Geo_Element * Geo_Element)91 void Geo_CreateFacetsOfElement(struct Geo_Element * Geo_Element)
92 {
93   int  Nbr_Entities2, * D_Element ;
94 
95   D_Element = Geo_GetIM_Dfe(Geo_Element->Type, &Nbr_Entities2) ;
96   if(!Nbr_Entities2) return;
97   Geo_CreateEntitiesOfElement(Nbr_Entities2, D_Element,
98 			      Geo_Element->NbrEdges, Geo_Element->NumEdges,
99 			      &Geo_Element->NbrFacets, &Geo_Element->NumFacets,
100 			      &CurrentGeoData->NbrElementsWithFacets,
101 			      &CurrentGeoData->NumCurrentFacet,
102 			      CurrentGeoData->FacetsXEdges) ;
103 }
104 
105 /* ------------------------------------------------------------------------ */
106 /*  G e o _ G e t I M _ D e n                                               */
107 /* ------------------------------------------------------------------------ */
108 
Geo_GetIM_Den(int Type_Element,int * Nbe)109 int *Geo_GetIM_Den(int Type_Element, int * Nbe)
110 {
111 
112   switch (Type_Element) {
113   case POINT_ELEMENT :
114     *Nbe = NbrEdges_Point       ; return(NULL) ;
115 
116   case LINE   : case LINE_2 :
117   case LINE_3 : case LINE_4 :
118     *Nbe = NbrEdges_Line        ; return(*Den_Line) ;
119 
120   case TRIANGLE   : case TRIANGLE_2 :
121   case TRIANGLE_3 : case TRIANGLE_4 :
122     *Nbe = NbrEdges_Triangle    ; return(*Den_Triangle) ;
123 
124   case QUADRANGLE   : case QUADRANGLE_2 : case QUADRANGLE_2_8N :
125   case QUADRANGLE_3 : case QUADRANGLE_4 :
126     *Nbe = NbrEdges_Quadrangle  ; return(*Den_Quadrangle) ;
127 
128   case TETRAHEDRON   : case TETRAHEDRON_2 :
129   case TETRAHEDRON_3 : case TETRAHEDRON_4 :
130     *Nbe = NbrEdges_Tetrahedron ; return(*Den_Tetrahedron) ;
131 
132   case HEXAHEDRON   : case HEXAHEDRON_2 : case HEXAHEDRON_2_20N :
133   case HEXAHEDRON_3 : case HEXAHEDRON_4 :
134     *Nbe = NbrEdges_Hexahedron  ; return(*Den_Hexahedron) ;
135 
136   case PRISM   : case PRISM_2 : case PRISM_2_15N :
137   case PRISM_3 : case PRISM_4 :
138     *Nbe = NbrEdges_Prism       ; return(*Den_Prism) ;
139 
140   case PYRAMID : case PYRAMID_2 : case PYRAMID_2_13N :
141   case PYRAMID_3 : // case PYRAMID_4
142     *Nbe = NbrEdges_Pyramid     ; return(*Den_Pyramid) ;
143 
144   default :
145     Message::Error("Unknown incidence matrix for element type %d", Type_Element);
146     return(NULL) ;
147   }
148 }
149 
150 /* ------------------------------------------------------------------------ */
151 /*  G e o _ G e t I M _ D f e                                               */
152 /* ------------------------------------------------------------------------ */
153 
Geo_GetIM_Dfe(int Type_Element,int * Nbf)154 int *Geo_GetIM_Dfe(int Type_Element, int * Nbf)
155 {
156   switch (Type_Element) {
157   case POINT_ELEMENT :
158     *Nbf = NbrFacets_Point       ; return(NULL) ;
159 
160   case LINE   : case LINE_2 :
161   case LINE_3 : case LINE_4 :
162     *Nbf = NbrFacets_Line        ; return(NULL) ;
163 
164   case TRIANGLE   : case TRIANGLE_2 :
165   case TRIANGLE_3 : case TRIANGLE_4 :
166     *Nbf = NbrFacets_Triangle    ; return(*Dfe_Triangle) ;
167 
168   case QUADRANGLE   : case QUADRANGLE_2 : case QUADRANGLE_2_8N :
169   case QUADRANGLE_3 : case QUADRANGLE_4 :
170     *Nbf = NbrFacets_Quadrangle  ; return(*Dfe_Quadrangle) ;
171 
172   case TETRAHEDRON   : case TETRAHEDRON_2 :
173   case TETRAHEDRON_3 : case TETRAHEDRON_4 :
174      *Nbf = NbrFacets_Tetrahedron ; return(*Dfe_Tetrahedron) ;
175 
176   case HEXAHEDRON   : case HEXAHEDRON_2 : case HEXAHEDRON_2_20N :
177   case HEXAHEDRON_3 : case HEXAHEDRON_4 :
178     *Nbf = NbrFacets_Hexahedron  ; return(*Dfe_Hexahedron) ;
179 
180   case PRISM   : case PRISM_2 : case PRISM_2_15N :
181   case PRISM_3 : case PRISM_4 :
182     *Nbf = NbrFacets_Prism       ; return(*Dfe_Prism) ;
183 
184   case PYRAMID : case PYRAMID_2 : case PYRAMID_2_13N :
185   case PYRAMID_3 : // case PYRAMID_4
186     *Nbf = NbrFacets_Pyramid     ; return(*Dfe_Pyramid) ;
187 
188   default :
189     Message::Error("Unknown incidence matrix for element type %d", Type_Element);
190     return(NULL) ;
191   }
192 }
193 
194 /* ------------------------------------------------------------------------ */
195 /*  G e o _ G e t I M _ D f n                                               */
196 /* ------------------------------------------------------------------------ */
197 
Geo_GetIM_Dfn(int Type_Element,int * Nbf)198 int *Geo_GetIM_Dfn(int Type_Element, int * Nbf)
199 {
200   switch (Type_Element) {
201   case POINT_ELEMENT :
202     *Nbf = NbrFacets_Point       ; return(NULL) ;
203 
204   case LINE   : case LINE_2 :
205   case LINE_3 : case LINE_4 :
206     *Nbf = NbrFacets_Line        ; return(NULL) ;
207 
208   case TRIANGLE   : case TRIANGLE_2 :
209   case TRIANGLE_3 : case TRIANGLE_4 :
210     *Nbf = NbrFacets_Triangle    ; return(*Dfn_Triangle) ;
211 
212   case QUADRANGLE   : case QUADRANGLE_2 : case QUADRANGLE_2_8N :
213   case QUADRANGLE_3 : case QUADRANGLE_4 :
214     *Nbf = NbrFacets_Quadrangle  ; return(*Dfn_Quadrangle) ;
215 
216   case TETRAHEDRON   : case TETRAHEDRON_2 :
217   case TETRAHEDRON_3 : case TETRAHEDRON_4 :
218     *Nbf = NbrFacets_Tetrahedron ; return(*Dfn_Tetrahedron) ;
219 
220   case HEXAHEDRON   : case HEXAHEDRON_2 : case HEXAHEDRON_2_20N :
221   case HEXAHEDRON_3 : case HEXAHEDRON_4 :
222     *Nbf = NbrFacets_Hexahedron  ; return(*Dfn_Hexahedron) ;
223 
224   case PRISM   : case PRISM_2 : case PRISM_2_15N :
225   case PRISM_3 : case PRISM_4 :
226     *Nbf = NbrFacets_Prism       ; return(*Dfn_Prism) ;
227 
228   case PYRAMID : case PYRAMID_2 : case PYRAMID_2_13N :
229   case PYRAMID_3 : // case PYRAMID_4
230     *Nbf = NbrFacets_Pyramid     ; return(*Dfn_Pyramid) ;
231 
232   default :
233     Message::Error("Unknown incidence matrix for element type %d", Type_Element);
234     return(NULL) ;
235   }
236 }
237 
238 /* ------------------------------------------------------------------------ */
239 /*  G e o _ G e t I M _ D e n _ X p                                         */
240 /* ------------------------------------------------------------------------ */
241 
Geo_GetIM_Den_Xp(int Type_Element,int * Nbe,int * Nbn)242 int * Geo_GetIM_Den_Xp(int Type_Element, int * Nbe, int * Nbn)
243 {
244   switch (Type_Element) {
245   case POINT_ELEMENT :
246     *Nbe = NbrEdges_Point ; *Nbn = NbrNodes_Point ;
247     return(NULL) ;
248 
249   case LINE   : case LINE_2 :
250   case LINE_3 : case LINE_4 :
251     *Nbe = NbrEdges_Line ; *Nbn = NbrNodes_Line ;
252     return(Den_Line_Xp) ;
253 
254   case TRIANGLE   : case TRIANGLE_2 :
255   case TRIANGLE_3 : case TRIANGLE_4 :
256     *Nbe = NbrEdges_Triangle ; *Nbn = NbrNodes_Triangle ;
257     return(Den_Triangle_Xp) ;
258 
259   case QUADRANGLE   : case QUADRANGLE_2 : case QUADRANGLE_2_8N :
260   case QUADRANGLE_3 : case QUADRANGLE_4 :
261     *Nbe = NbrEdges_Quadrangle ; *Nbn = NbrNodes_Quadrangle ;
262     return(Den_Quadrangle_Xp) ;
263 
264   case TETRAHEDRON   : case TETRAHEDRON_2 :
265   case TETRAHEDRON_3 : case TETRAHEDRON_4 :
266     *Nbe = NbrEdges_Tetrahedron ; *Nbn = NbrNodes_Tetrahedron ;
267     return(Den_Tetrahedron_Xp) ;
268 
269   case HEXAHEDRON   : case HEXAHEDRON_2 : case HEXAHEDRON_2_20N :
270   case HEXAHEDRON_3 : case HEXAHEDRON_4 :
271     *Nbe = NbrEdges_Hexahedron ; *Nbn = NbrNodes_Hexahedron ;
272     return(Den_Hexahedron_Xp) ;
273 
274   case PRISM   : case PRISM_2 : case PRISM_2_15N :
275   case PRISM_3 : case PRISM_4 :
276     *Nbe = NbrEdges_Prism ; *Nbn = NbrNodes_Prism ;
277     return(Den_Prism_Xp) ;
278 
279   case PYRAMID : case PYRAMID_2 : case PYRAMID_2_13N :
280   case PYRAMID_3 : // case PYRAMID_4
281     *Nbe = NbrEdges_Pyramid ; *Nbn = NbrNodes_Pyramid ;
282     return(Den_Pyramid_Xp) ;
283 
284   default :
285     Message::Error("Unknown incidence matrix for element type %d", Type_Element);
286     return(NULL) ;
287   }
288 }
289 
290 /* ------------------------------------------------------------------------ */
291 /*  G e o _ G e t I M _ D f e _ X p                                         */
292 /* ------------------------------------------------------------------------ */
293 
Geo_GetIM_Dfe_Xp(int Type_Element,int * nbf,int * nbe)294 int * Geo_GetIM_Dfe_Xp(int Type_Element, int * nbf, int * nbe)
295 {
296   switch (Type_Element) {
297   case POINT_ELEMENT :
298     *nbf = NbrFacets_Point ; *nbe = NbrEdges_Point ;
299     return(NULL) ;
300 
301   case LINE   : case LINE_2 :
302   case LINE_3 : case LINE_4 :
303     *nbf = NbrFacets_Line ; *nbe = NbrEdges_Line ;
304     return(NULL) ;
305 
306   case TRIANGLE   : case TRIANGLE_2 :
307   case TRIANGLE_3 : case TRIANGLE_4 :
308     *nbf = NbrFacets_Triangle ; *nbe = NbrEdges_Triangle ;
309     return(Dfe_Triangle_Xp) ;
310 
311   case QUADRANGLE   : case QUADRANGLE_2 : case QUADRANGLE_2_8N :
312   case QUADRANGLE_3 : case QUADRANGLE_4 :
313     *nbf = NbrFacets_Quadrangle ; *nbe = NbrEdges_Quadrangle ;
314     return(Dfe_Quadrangle_Xp) ;
315 
316   case TETRAHEDRON   : case TETRAHEDRON_2 :
317   case TETRAHEDRON_3 : case TETRAHEDRON_4 :
318     *nbf = NbrFacets_Tetrahedron ; *nbe = NbrEdges_Tetrahedron ;
319     return(Dfe_Tetrahedron_Xp) ;
320 
321   case HEXAHEDRON   : case HEXAHEDRON_2 : case HEXAHEDRON_2_20N :
322   case HEXAHEDRON_3 : case HEXAHEDRON_4 :
323     *nbf = NbrFacets_Hexahedron ; *nbe = NbrEdges_Hexahedron ;
324     return(Dfe_Hexahedron_Xp) ;
325 
326   case PRISM   : case PRISM_2 : case PRISM_2_15N :
327   case PRISM_3 : case PRISM_4 :
328     *nbf = NbrFacets_Prism ; *nbe = NbrEdges_Prism ;
329     return(Dfe_Prism_Xp) ;
330 
331   case PYRAMID : case PYRAMID_2 : case PYRAMID_2_13N :
332   case PYRAMID_3 : // case PYRAMID_4
333     *nbf = NbrFacets_Pyramid ; *nbe = NbrEdges_Pyramid ;
334     return(Dfe_Pyramid_Xp) ;
335 
336   default :
337     Message::Error("Unknown incidence matrix for element type %d", Type_Element);
338     return(NULL) ;
339   }
340 }
341 
342 /* ------------------------------------------------------------------------ */
343 /*  G e o _ C r e a t e E n t i t i e s O f E l e m e n t                   */
344 /* ------------------------------------------------------------------------ */
345 
Geo_CreateEntitiesOfElement(int Nbr_Entities2,int * D_Element,int Geo_Element_NbrEntities1,int * Geo_Element_NumEntities1,int * Geo_Element_NbrEntities2,int ** Geo_Element_NumEntities2,int * Geo_NbrElementsWithEntities2,int * Geo_NumCurrentEntity2,Tree_T * Geo_Entities2XEntities1)346 void Geo_CreateEntitiesOfElement
347   (int Nbr_Entities2, int * D_Element,
348    int   Geo_Element_NbrEntities1, int  * Geo_Element_NumEntities1,
349    int * Geo_Element_NbrEntities2, int ** Geo_Element_NumEntities2,
350    int * Geo_NbrElementsWithEntities2,
351    int * Geo_NumCurrentEntity2, Tree_T * Geo_Entities2XEntities1)
352 {
353   int  i, j, Nbr_Entities1, Num_Entities1[NBR_MAX_SUBENTITIES_IN_ELEMENT], Sign_Entity2 ;
354   int  * Entity_P, Entity ;
355   struct Entity2XEntity1  Entity2XEntities1, * Entity2XEntities1_P ;
356 
357   *Geo_Element_NbrEntities2 = Nbr_Entities2 ;
358   *Geo_Element_NumEntities2 = (int *)Malloc(Nbr_Entities2 * sizeof(int)) ;
359   (*Geo_NbrElementsWithEntities2)++ ;
360 
361   for (i = 0 ; i < Nbr_Entities2 ; i++) {
362 
363     Entity_P = D_Element + i * NBR_MAX_SUBENTITIES_IN_ELEMENT ;
364     Nbr_Entities1 = 0 ;
365     while ((Entity = *(Entity_P++)))
366       Num_Entities1[Nbr_Entities1++] = (Entity > 0)?
367 	Geo_Element_NumEntities1[Entity-1] : - Geo_Element_NumEntities1[-Entity-1] ;
368 
369     qsort(Num_Entities1, Nbr_Entities1, sizeof(int), fcmp_absint) ;
370 
371     if (Num_Entities1[0] < 0) {
372       Sign_Entity2 = -1 ;
373       for (j = 0 ; j < Nbr_Entities1 ; j++)  Num_Entities1[j] *= -1 ;
374     }
375     else
376       Sign_Entity2 = 1 ;
377 
378     Entity2XEntities1.NbrEntities = Nbr_Entities1 ;
379     Entity2XEntities1.NumEntities = Num_Entities1 ;
380 
381     if ((Entity2XEntities1_P = (struct Entity2XEntity1*)
382 	 Tree_PQuery(Geo_Entities2XEntities1, &Entity2XEntities1)) == NULL) {
383       Entity2XEntities1.Num         = ++(*Geo_NumCurrentEntity2) ;
384       Entity2XEntities1.NumEntities = (int *)Malloc(Nbr_Entities1*sizeof(int)) ;
385       for (j = 0 ; j < Nbr_Entities1 ; j++)
386 	Entity2XEntities1.NumEntities[j] = Num_Entities1[j] ;
387 
388       Tree_Add(Geo_Entities2XEntities1, &Entity2XEntities1) ;
389       (*Geo_Element_NumEntities2)[i] = Entity2XEntities1.Num    * Sign_Entity2 ;
390     }
391     else
392       (*Geo_Element_NumEntities2)[i] = Entity2XEntities1_P->Num * Sign_Entity2 ;
393   }
394 }
395 
396 /* ------------------------------------------------------------------------ */
397 /*  f c m p _ E 2 X E 1                                                     */
398 /* ------------------------------------------------------------------------ */
399 
fcmp_E2XE1(const void * a,const void * b)400 int fcmp_E2XE1(const void * a, const void * b)
401 {
402   int  i ;
403 
404   if (((struct Entity2XEntity1 *)a)->NbrEntities !=
405       ((struct Entity2XEntity1 *)b)->NbrEntities)
406     return
407       ((struct Entity2XEntity1 *)a)->NbrEntities -
408       ((struct Entity2XEntity1 *)b)->NbrEntities ;
409 
410   for (i = 0 ; i < ((struct Entity2XEntity1 *)a)->NbrEntities ; i++) {
411     if (((struct Entity2XEntity1 *)a)->NumEntities[i] >
412 	((struct Entity2XEntity1 *)b)->NumEntities[i])   return  1 ;
413     if (((struct Entity2XEntity1 *)a)->NumEntities[i] <
414 	((struct Entity2XEntity1 *)b)->NumEntities[i])   return -1 ;
415   }
416 
417   return 0 ;
418 }
419 
420 /* ------------------------------------------------------------------------ */
421 /*  f r e e _ E 2 X E 1                                                     */
422 /* ------------------------------------------------------------------------ */
423 
free_E2XE1(void * a,void * b)424 void free_E2XE1(void * a, void *b)
425 {
426   Free(((struct Entity2XEntity1 *)a)->NumEntities);
427 }
428 
429 /* ------------------------------------------------------------------------ */
430 /*  G e o _ W r i t e F i l e P R E                                         */
431 /* ------------------------------------------------------------------------ */
432 
Geo_WriteFilePRE(struct GeoData * GeoData_P,List_T * Group_L)433 void Geo_WriteFilePRE(struct GeoData * GeoData_P, List_T * Group_L)
434 {
435   if(Message::GetIsCommWorld() && Message::GetCommRank()) return;
436 
437   int  i, Nbr_Elements, j, Index_Group, Nbr_Entities, * Num_Entities ;
438   struct Geo_Element  * Geo_Element_P0, * Geo_Element_P ;
439   struct Group  * Group_P ;
440 
441   Nbr_Elements = List_Nbr(GeoData_P->Elements) ;
442 
443   /*  E l e m e n t s X E d g e s  */
444 
445   if (Nbr_Elements && GeoData_P->NumCurrentEdge) {
446     fprintf(File_PRE, "$ElementsXEdges\n") ;
447     fprintf(File_PRE, "%d %d\n", GeoData_P->Num, GeoData_P->NbrElementsWithEdges) ;
448     Geo_Element_P0 = (struct Geo_Element*)List_Pointer(GeoData_P->Elements, 0) ;
449     for (i = 0 ; i < Nbr_Elements ; i++) {
450       if ((Geo_Element_P0 + i)->NbrEdges) {
451 	Geo_Element_P = Geo_Element_P0 + i ;
452 	fprintf(File_PRE, "%d %d", i, Geo_Element_P->NbrEdges) ;
453 	for (j = 0 ; j < Geo_Element_P->NbrEdges ; j++)
454 	  fprintf(File_PRE, " %d", Geo_Element_P->NumEdges[j]) ;
455 	fprintf(File_PRE, "\n") ;
456       }
457     }
458     fprintf(File_PRE, "$EndElementsXEdges\n") ;
459 
460     if (Flag_XDATA) {
461       fprintf(File_PRE, "$EdgesXNodes  /* Never used, only for test */\n") ;
462       fprintf(File_PRE, "%d %d\n", GeoData_P->Num, Tree_Nbr(GeoData_P->EdgesXNodes)) ;
463       Tree_Action(GeoData_P->EdgesXNodes, Geo_WriteEntities2XEntities1) ;
464       fprintf(File_PRE, "$EndEdgesXNodes\n") ;
465     }
466   }
467 
468   /*  E l e m e n t s X F a c e t s  */
469 
470   if (Nbr_Elements && GeoData_P->NumCurrentFacet) {
471     fprintf(File_PRE, "$ElementsXFacets\n") ;
472     fprintf(File_PRE, "%d %d\n", GeoData_P->Num, GeoData_P->NbrElementsWithFacets) ;
473     Geo_Element_P0 = (struct Geo_Element*)List_Pointer(GeoData_P->Elements, 0) ;
474     for (i = 0 ; i < Nbr_Elements ; i++) {
475       if ((Geo_Element_P0 + i)->NbrFacets) {
476 	Geo_Element_P = Geo_Element_P0 + i ;
477 	fprintf(File_PRE, "%d %d", i, Geo_Element_P->NbrFacets) ;
478 	for (j = 0 ; j < Geo_Element_P->NbrFacets ; j++)
479 	  fprintf(File_PRE, " %d", Geo_Element_P->NumFacets[j]) ;
480 	fprintf(File_PRE, "\n") ;
481       }
482     }
483     fprintf(File_PRE, "$EndElementsXFacets\n") ;
484 
485     if (Flag_XDATA) {
486       fprintf(File_PRE, "$FacetsXEdges  /* Never used, only for test */\n") ;
487       fprintf(File_PRE, "%d %d\n", GeoData_P->Num, Tree_Nbr(GeoData_P->FacetsXEdges)) ;
488       Tree_Action(GeoData_P->FacetsXEdges, Geo_WriteEntities2XEntities1) ;
489       fprintf(File_PRE, "$EndFacetsXEdges\n") ;
490     }
491   }
492 
493   /*  E x t e n d e d G r o u p  */
494 
495   if (GeoData_P->GroupForPRE != NULL) {
496     for (i = 0 ; i < List_Nbr(GeoData_P->GroupForPRE) ; i++) {
497       List_Read(GeoData_P->GroupForPRE, i, &Index_Group) ;
498       Group_P = (struct Group*)List_Pointer(Group_L, Index_Group) ;
499 
500       fprintf(File_PRE, "$ExtendedGroup  /* %s */\n", Group_P->Name) ;
501       fprintf(File_PRE, "%d %d\n",
502 	      Index_Group, Nbr_Entities = List_Nbr(Group_P->ExtendedList)) ;
503       if (Nbr_Entities) {
504 	Num_Entities = (int*)List_Pointer(Group_P->ExtendedList, 0) ;
505 	  for (j = 0 ; j < Nbr_Entities ; j++) {
506 	    fprintf(File_PRE, (j%10)? " %d" : "%d", Num_Entities[j]) ;
507 	    if (j%10 == 9)  fprintf(File_PRE, "\n") ;
508 	  }
509 	if (j%10)  fprintf(File_PRE, "\n") ;
510 	fprintf(File_PRE, "$EndExtendedGroup\n") ;
511       }
512     }
513   }
514 }
515 
516 /* --------------------------------------------------------- */
517 /*  G e o _ W r i t e E n t i t i e s 2 X E n t i t i e s 1  */
518 /* --------------------------------------------------------- */
519 
Geo_WriteEntities2XEntities1(void * a,void * b)520 void Geo_WriteEntities2XEntities1(void * a, void * b)
521 {
522   int  i ;
523 
524   fprintf(File_PRE, "%d %d", ((struct Entity2XEntity1 *)a)->Num,
525 	  ((struct Entity2XEntity1 *)a)->NbrEntities) ;
526   for (i = 0 ; i < ((struct Entity2XEntity1 *)a)->NbrEntities ; i++)
527     fprintf(File_PRE, " %d", ((struct Entity2XEntity1 *)a)->NumEntities[i]) ;
528   fprintf(File_PRE, "\n") ;
529 }
530 
531 /* ------------------------------------------------------------------------ */
532 /*  G e o _ R e a d F i l e P R E                                           */
533 /* ------------------------------------------------------------------------ */
534 
Geo_ReadFilePRE(struct GeoData * GeoData_P0,int NbrGeoData,List_T * Group_L)535 void Geo_ReadFilePRE(struct GeoData * GeoData_P0, int NbrGeoData,
536 		      List_T * Group_L)
537 {
538   Message::Barrier();
539 
540   struct GeoData      * GeoData_P ;
541   struct Geo_Element  * Geo_Element_P0, * Geo_Element_P ;
542   struct Group        * Group_P ;
543   int   i, Index_Element, Nbr_Entities, j, Index_Group, Num_Entity ;
544   int   GeoDataIndex ;
545   char  String[256] ;
546 
547   for(GeoDataIndex = 0 ; GeoDataIndex < NbrGeoData ; GeoDataIndex++){
548     if(!(GeoData_P0 + GeoDataIndex)->Elements){
549       Message::Warning("No Element in GeoData %d", GeoDataIndex);
550       return;
551     }
552   }
553 
554   while (1) {
555 
556     do {
557       if(!fgets(String, sizeof(String), File_PRE) || feof(File_PRE))
558         break ;
559     } while (String[0] != '$') ;
560 
561     if (feof(File_PRE))  break ;
562 
563     /*  E l e m e n t s X E d g e s  */
564 
565     if (!strncmp(&String[1], "ElementsXEdges", 14)) {
566 
567       if(fscanf(File_PRE, "%d", &GeoDataIndex) != 1){
568         Message::Error("Could not read GeoData index");
569         return;
570       }
571       if(GeoDataIndex > NbrGeoData-1){
572 	Message::Error("Unknown GeoData: %d", GeoDataIndex);
573         return;
574       }
575 
576       GeoData_P = GeoData_P0 + GeoDataIndex ;
577       Geo_Element_P0 = (struct Geo_Element*)List_Pointer(GeoData_P->Elements, 0) ;
578 
579       if(fscanf(File_PRE, "%d", &GeoData_P->NbrElementsWithEdges) != 1){
580         Message::Error("Could not read number of elements with edges");
581         return;
582       }
583       for (i = 0 ; i < GeoData_P->NbrElementsWithEdges ; i++) {
584 	if(fscanf(File_PRE, "%d %d", &Index_Element, &Nbr_Entities) != 2){
585           Message::Error("Could not read element index and number of edges");
586           return;
587         }
588 	Geo_Element_P = Geo_Element_P0 + Index_Element ;
589 	Geo_Element_P->NbrEdges = Nbr_Entities ;
590 	Geo_Element_P->NumEdges = (int *)Malloc(Nbr_Entities * sizeof(int)) ;
591 	for (j = 0 ; j < Geo_Element_P->NbrEdges ; j++){
592 	  if(fscanf(File_PRE, "%d", &Geo_Element_P->NumEdges[j]) != 1){
593             Message::Error("Could not read edge");
594             return;
595           }
596         }
597       }
598     }
599 
600     /*  E l e m e n t s X F a c e t s  */
601 
602     else if (!strncmp(&String[1], "ElementsXFacets", 15)) {
603 
604       if(fscanf(File_PRE, "%d", &GeoDataIndex) != 1){
605         Message::Error("Could not read GeoData index");
606         return;
607       }
608       if(GeoDataIndex > NbrGeoData-1){
609 	Message::Error("Unknown GeoData: %d", GeoDataIndex);
610         return;
611       }
612 
613       GeoData_P = GeoData_P0 + GeoDataIndex ;
614       Geo_Element_P0 = (struct Geo_Element*)List_Pointer(GeoData_P->Elements, 0) ;
615 
616       if(fscanf(File_PRE, "%d", &GeoData_P->NbrElementsWithFacets) != 1){
617         Message::Error("Could not read number of elements with facets");
618         return;
619       }
620       for (i = 0 ; i < GeoData_P->NbrElementsWithFacets ; i++) {
621 	if(fscanf(File_PRE, "%d %d", &Index_Element, &Nbr_Entities) != 2){
622           Message::Error("Could not read element index and number of facets");
623           return;
624         }
625 	Geo_Element_P = Geo_Element_P0 + Index_Element ;
626 	Geo_Element_P->NbrFacets = Nbr_Entities ;
627 	Geo_Element_P->NumFacets = (int *)Malloc(Nbr_Entities * sizeof(int)) ;
628 	for (j = 0 ; j < Geo_Element_P->NbrFacets ; j++){
629 	  if(fscanf(File_PRE, "%d", &Geo_Element_P->NumFacets[j]) != 1){
630             Message::Error("Could not read facet");
631             return;
632           }
633         }
634       }
635     }
636 
637     /*  E x t e  n d e d G r o u p  */
638 
639     else if (!strncmp(&String[1], "ExtendedGroup", 13)) {
640 
641       if(fscanf(File_PRE, "%d %d", &Index_Group, &Nbr_Entities) != 2){
642         Message::Error("Could not read extended group index and number of entities");
643         return;
644       }
645       Group_P = (struct Group*)List_Pointer(Group_L, Index_Group) ;
646       Group_P->ExtendedList = List_Create(Nbr_Entities, 1, sizeof(int)) ;
647       for (i = 0 ; i < Nbr_Entities ; i++) {
648 	if(fscanf(File_PRE, "%d", &Num_Entity) != 1){
649           Message::Error("Could not read entity");
650           return;
651         }
652 	List_Add(Group_P->ExtendedList, &Num_Entity) ;
653       }
654     }
655 
656     do {
657       if(!fgets(String, sizeof(String), File_PRE) || feof(File_PRE))
658         break;
659     } while (String[0] != '$') ;
660 
661   }   /* while 1 ... */
662 }
663 
664 /* ------------------------------------------------------------------------ */
665 /*  G e o  _ A d d G r o u p F o r P R E                                    */
666 /* ------------------------------------------------------------------------ */
667 
Geo_AddGroupForPRE(int Num)668 void Geo_AddGroupForPRE(int Num)
669 {
670   if (CurrentGeoData->GroupForPRE == NULL)
671     CurrentGeoData->GroupForPRE = List_Create( 2, 2, sizeof(int)) ;
672 
673   List_Add(CurrentGeoData->GroupForPRE, &Num) ;
674 }
675