1 
2 #include <extUtil.h>
3 
4 #define MAXVALUE 2147483647
5 
6 
renumberfrd(int firstelem,int firstnode,Summen * anz,Nodes ** nptr,Elements ** eptr,Datasets ** lptr,int ** enew_ptr,int ** nnew_ptr)7 int renumberfrd( int firstelem, int firstnode, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, int **enew_ptr, int **nnew_ptr )
8 {
9   static Nodes     *node;
10   static Elements  *elem;
11   static Datasets *lcase;
12 
13   int  i,n, ipuf;
14   int nlc, ncmp;
15   int *newnode, *newelem;
16   double *newnode_x, *newnode_y, *newnode_z, *dat;
17 
18   node=*nptr;
19   elem=*eptr;
20   lcase=*lptr;
21 
22   if ( (newnode = (int *)malloc( (anz->nmax+1)*sizeof(int) )) == NULL )
23   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
24   for(i=0; i<=anz->nmax; i++) newnode[i]=0;
25   if ( (newelem = (int *)malloc( (anz->emax+1)*sizeof(int) )) == NULL )
26   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
27   for(i=0; i<=anz->emax; i++) newelem[i]=0;
28   if ( (dat = (double *)malloc( (anz->nmax+firstnode)*sizeof(double) )) == NULL )
29   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
30   if ( (newnode_x = (double *)malloc( (anz->nmax+1)*sizeof(double) )) == NULL )
31   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
32   if ( (newnode_y = (double *)malloc( (anz->nmax+1)*sizeof(double) )) == NULL )
33   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
34   if ( (newnode_z = (double *)malloc( (anz->nmax+1)*sizeof(double) )) == NULL )
35   { printf("\n\n ERROR: malloc failed in renumberfrd()\n\n") ; return(-1); }
36 
37   if (anz->l > 0)
38   {
39     for (nlc=0; nlc< anz->l; nlc++)
40     {
41       /* check if the data of the specified lcase (Dataset) are already available */
42       if (!lcase[nlc].loaded)
43       {
44         if( readfrdblock(nlc, anz, node, lcase )==-1)
45         {
46           printf("ERROR: Could not read data for Dataset:%d\n", nlc+1);
47           return(-1);
48         }
49       }
50     }
51   }
52 
53   if (anz->n > 0)
54   {
55     anz->nmax=-MAXVALUE;  anz->nmin= MAXVALUE;
56     for (i=0; i<anz->n; i++)
57     {
58       newnode[node[i].nr]=i+firstnode;
59       newnode_x[node[i].nr]=node[node[i].nr].nx;
60       newnode_y[node[i].nr]=node[node[i].nr].ny;
61       newnode_z[node[i].nr]=node[node[i].nr].nz;
62       if (newnode[node[i].nr] >  anz->nmax)  anz->nmax=newnode[node[i].nr];
63       if (newnode[node[i].nr] <  anz->nmin)  anz->nmin=newnode[node[i].nr];
64     }
65   }
66 
67   if (anz->e > 0)
68   {
69     anz->emax=-MAXVALUE;  anz->emin=MAXVALUE;
70     for (i=0; i<anz->e; i++)
71     {
72       ipuf=0;
73       if (elem[i].type == 1) ipuf = 8;  /* CHEXA8  */
74       if (elem[i].type == 2) ipuf = 6;  /* CPENTA6   */
75       if (elem[i].type == 3) ipuf = 4;  /* CTET4   */
76       if (elem[i].type == 4) ipuf = 20; /* CHEXA20 */
77       if (elem[i].type == 5) ipuf = 15; /* CPENTA15  */
78       if (elem[i].type == 6) ipuf = 10; /* CTET10  */
79       if (elem[i].type == 7) ipuf = 3;  /* CTRI3   */
80       if (elem[i].type == 8) ipuf = 6;  /* CTRI6   */
81       if (elem[i].type == 9) ipuf = 4;  /* CQUAD4  */
82       if (elem[i].type == 10) ipuf = 8; /* CQUAD8  */
83       if (elem[i].type == 11) ipuf = 2;  /* CBEAM2  */
84       if (elem[i].type == 12) ipuf = 3;  /* CBEAM3  */
85       if (ipuf==0)
86       {
87         printf (" elem(%d) not a known type (%d)\n", elem[i].nr, elem[i].type);
88       }
89       else
90       {
91         newelem[elem[i].nr]=i+firstelem;
92         elem[i].nr=i+firstelem;
93         if (elem[i].nr >  anz->emax)  anz->emax=elem[i].nr;
94         if (elem[i].nr <  anz->emin)  anz->emin=elem[i].nr;
95         for (n=0; n<ipuf; n++)
96         {
97           elem[i].nod[n]=newnode[elem[i].nod[n]];
98         }
99       }
100     }
101   }
102   if (anz->l > 0)
103   {
104     for (nlc=0; nlc< anz->l; nlc++)
105     {
106       for (ncmp=0; ncmp<lcase[nlc].ncomps; ncmp++ )
107       {
108         for (i=0; i<anz->n; i++)
109         {
110           dat[node[i].nr]=lcase[nlc].dat[ncmp][node[i].nr] ;
111         }
112         if ( (lcase[nlc].dat[ncmp] = (float *)realloc( (float *)lcase[nlc].dat[ncmp] ,(anz->nmax+1) * sizeof(float))) == NULL )
113         {
114           printf("\n\n ERROR: realloc failed\n\n" );
115           return(-1);
116         }
117         for (i=0; i<=anz->nmax; i++)
118         {
119           lcase[nlc].dat[ncmp][i]=0.;
120         }
121         for (i=0; i<anz->n; i++)
122         {
123           lcase[nlc].dat[ncmp][newnode[node[i].nr]]=dat[node[i].nr];
124         }
125       }
126     }
127   }
128   if (anz->n > 0)
129   {
130     if ( (node = (Nodes *)realloc((Nodes *)node, (anz->nmax+1) * sizeof(Nodes))) == NULL )
131     {
132       printf("\n\n ERROR: realloc failed, nodenr\n") ;
133       return(-1);
134     }
135     for (i=0; i<anz->n; i++)
136     {
137       node[newnode[node[i].nr]].indx=i;
138       node[newnode[node[i].nr]].nx=newnode_x[node[i].nr];
139       node[newnode[node[i].nr]].ny=newnode_y[node[i].nr];
140       node[newnode[node[i].nr]].nz=newnode_z[node[i].nr];
141       node[i].nr=newnode[node[i].nr];
142     }
143   }
144 
145   *enew_ptr=newelem;
146   *nnew_ptr=newnode;
147   *nptr =  node; *eptr = elem; *lptr = lcase;
148 
149   free(newnode_x);
150   free(newnode_y);
151   free(newnode_z);
152   free(dat);
153   return (1);
154 }
155 
156