1 /* --------------------------------------------------------------------  */
2 /*                          CALCULIX                                     */
3 /*                   - GRAPHICAL INTERFACE -                             */
4 /*                                                                       */
5 /*     A 3-dimensional pre- and post-processor for finite elements       */
6 /*              Copyright (C) 1996 Klaus Wittig                          */
7 /*                                                                       */
8 /*     This program is free software; you can redistribute it and/or     */
9 /*     modify it under the terms of the GNU General Public License as    */
10 /*     published by the Free Software Foundation; version 2 of           */
11 /*     the License.                                                      */
12 /*                                                                       */
13 /*     This program is distributed in the hope that it will be useful,   */
14 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */
15 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
16 /*     GNU General Public License for more details.                      */
17 /*                                                                       */
18 /*     You should have received a copy of the GNU General Public License */
19 /*     along with this program; if not, write to the Free Software       */
20 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
21 /* --------------------------------------------------------------------  */
22 
23 #include <cgx.h>
24 
25 #define INTERPOL_MODE 0
26 
27 #define TEST 0
28 #define TEST1 0
29 
30 extern int printFlag;
31 
32 extern Scale     scale[1];
33 extern Summen    anz[1];
34 extern Nodes     *node;
35 extern Elements  *e_enqire;
36 extern Datasets *lcase;
37 
38 extern Sets      *set;                     /* sets */
39 extern Points    *point;
40 extern Lines     *line;
41 extern Lcmb      *lcmb;
42 extern Gsur      *surf;
43 extern Gbod      *body;
44 extern Nurbs     *nurbs;
45 extern SumGeo    anzGeo[1];
46 
47 extern sem_t   sem_n;
48 
49 /* preliminary nodes, they will be deleded after the elements are created */
50 extern Summen    apre[1];
51 extern Nodes     *npre;
52 
53 /**********************************************************************************/
54 /* Fuellt ein xyz-feld mit den koordinaten einer Flaeche im ba raum, ausgehend    */
55 /* von daten im uv raum.                                                          */
56 /*                                                                                */
57 /*                                                                                */
58 /*                                                                                */
59 /*                                                                                */
60 /* in:                                                                            */
61 /* sur      surface-index                                                         */
62 /* div_l    feld mit den divisions der surface-edges                              */
63 /* div_a    ersatzdivision der 'a'-edges der surf.                                */
64 /* div_b    ersatzdivision der 'b'-edges der surf.                                */
65 /* sa1,sa2,sb1,sb2  Zuordnung der original-edges zu den a&b-edges                 */
66 /* offs_sa1    div_a-div_l[sa1], zur elementerzeugung notwendig                   */
67 /* offs_sa2    div_a-div_l[sa2]                                                   */
68 /*                                                                                */
69 /* out:                                                                           */
70 /* n_uv        nodeNr im uv-feld, die zusaetzlichen ersatz-stuetzpunkte sind      */
71 /*             nicht mit nodes belegt da sie bei der Vernetzung rausfallen        */
72 /* umax, vmax  anzahl der ersatz-stuetzpunkte in 'u' und 'v' bzw entlang edge     */
73 /*             '0' und '3' ( umax = div_(a|b) +1 )                                */
74 /* n_ba        nodeNr im ba-feld, siehe n_uv                                      */
75 /* amax, bmax  anzahl der ersatz-stuetzpunkte in 'a' und 'b'                      */
76 /*                         ( amax = div_a +1 )                                    */
77 /* x,y,z       f(u,v) aus dem surfmesher, alle u,v positionen sind belegt         */
78 /* x_ba..      f(b,a) aus dem surfmesher, alle b,a positionen sind belegt         */
79 /*                                                                                */
80 /*                                                                                */
81 /**********************************************************************************/
fillSurf_ba1(int sur,int * div_l,int div_a,int div_b,int sa1,int sa2,int sb1,int sb2,int * n_uv,int * n_ba,int offs1,int offs2,double * x,double * y,double * z,double * x_ba,double * y_ba,double * z_ba)82 int  fillSurf_ba1( int sur, int *div_l, int div_a, int div_b, int sa1, int sa2, int sb1, int sb2, int *n_uv, int *n_ba,  int offs1   , int offs2   , double *x, double *y, double *z, double *x_ba, double *y_ba, double *z_ba )
83 {
84   int n, u,v, b=0,a=0;
85   int nodnr;
86   double *lx, *ly, *lz;
87   int flag;
88   int amax, bmax, umax, vmax, sumax, svmax;
89 
90   int k;
91 
92       bmax=div_b+1;
93       amax=div_a+1;
94       if ((sa1==0)||(sa1==2))
95       {
96         umax=amax    ;
97         vmax=bmax    ;
98       }
99       else
100       {
101         umax=bmax    ;
102         vmax=amax    ;
103       }
104       sumax=div_l[0]+1;
105       svmax=div_l[3]+1;
106       edgeNodes( svmax, sumax, sur, n_uv );
107       k=0;
108 #if TEST
109       for (u=0; u<sumax; u++)
110       {
111         for (v=0; v<svmax; v++)
112 	{
113           printf("%d  n(%d,%d):%d  n:%d\n",k,u,v,n_uv[u*svmax+v], n_uv[k]); k++;
114 	}
115       }
116 #endif
117 
118       /* die Randknoten sind nun bekannt. es muessen nun ersatzkoordinaten */
119       /* mit dem spacing der ersatzdivisions berechnet werden. dazu wird  */
120       /* in einem feld aus koordinate(x,y oder z) und der lauflaenge s int-*/
121       /* erpoliert.                                                        */
122 
123       /* side 0 */
124       n=div_l[0]+1;        /* anzahl von original-nodes auf der line */
125       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
126           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
127           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
128       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
129       v=0;
130       for (u=0; u<n; u++)
131       {
132         nodnr=n_uv[u*svmax +v];
133     sem_wait(&sem_n);
134         lx[u]=npre[nodnr].nx;
135         ly[u]=npre[nodnr].ny;
136         lz[u]=npre[nodnr].nz;
137     sem_post(&sem_n);
138       }
139       v=0;
140       u=0;
141       flag=0; /* v const */
142       if( newEdgePositions( n, u,v, umax,vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
143       free(lx);free(ly);free(lz);
144 
145       /* side 1 */
146       n=div_l[3]+1;
147       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
148           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
149           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
150       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");   return(-1); }
151       u=div_l[0];
152       for (v=0; v<n; v++)
153       {
154         nodnr=n_uv[u*svmax +v];
155     sem_wait(&sem_n);
156         lx[v]=npre[nodnr].nx;
157         ly[v]=npre[nodnr].ny;
158         lz[v]=npre[nodnr].nz;
159     sem_post(&sem_n);
160       }
161       u=umax-1;
162       v=0;
163       flag=1; /* u const */
164       if( newEdgePositions( n, u,v, umax,vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
165       free(lx);free(ly);free(lz);
166 
167       /* side 2 */
168       n=div_l[0]+1;
169       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
170           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
171           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
172       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");   return(-1); }
173       v=div_l[3];
174       for (u=0; u<n; u++)
175       {
176         nodnr=n_uv[u*svmax +v];
177     sem_wait(&sem_n);
178         lx[u]=npre[nodnr].nx;
179         ly[u]=npre[nodnr].ny;
180         lz[u]=npre[nodnr].nz;
181     sem_post(&sem_n);
182       }
183       v=vmax-1;
184       u=0;
185       flag=0; /* v const */
186       if( newEdgePositions( n, u,v, umax, vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
187       free(lx);free(ly);free(lz);
188 
189       /* side 3 */
190       n=div_l[3]+1;
191       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
192           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
193           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
194       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
195       u=0;
196       for (v=0; v<n; v++)
197       {
198         nodnr=n_uv[u*svmax +v];
199     sem_wait(&sem_n);
200         lx[v]=npre[nodnr].nx;
201         ly[v]=npre[nodnr].ny;
202         lz[v]=npre[nodnr].nz;
203     sem_post(&sem_n);
204       }
205       u=0;
206       v=0;
207       flag=1; /* u const */
208       if( newEdgePositions( n, u,v, umax,vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
209       free(lx);free(ly);free(lz);
210 
211       surfMesh( &vmax, &umax, x, y, z);
212 
213       /* umspeichern der rand-nodes ins ba system */
214       k=0;
215       for (u=0; u< div_l[0]+1; u++)
216       {
217         for (v=0; v< div_l[3]+1; v++)
218         {
219         nodnr=n_uv[u*svmax +v];
220         if ((sb1==0)&&(sa1==3)) { b=u+ offs1            ; a=v                    ; }
221         if ((sb1==3)&&(sa1==2)) { b=vmax-v-1 - offs2   ; a=u                    ; }
222         if ((sb1==2)&&(sa1==1)) { b=umax-u-1 - offs2   ; a=vmax-v-1            ; }
223         if ((sb1==1)&&(sa1==0)) { b=v+ offs1            ; a=umax-u-1            ; }
224         if ((sb1==0)&&(sa1==1)) { b=umax-u-1 - offs2   ; a=v                    ; }
225         if ((sb1==3)&&(sa1==0)) { b=v+ offs1            ; a=u                    ;  }
226         if ((sb1==2)&&(sa1==3)) { b=u+ offs1             ; a=vmax-v-1            ;  }
227         if ((sb1==1)&&(sa1==2)) { b=vmax-v-1 - offs2   ; a=umax-u-1            ; }
228         n_ba[b* amax +a]=nodnr;
229 #if TEST
230   printf(" Fall  b:%d a:%d\n", b, a);
231 #endif
232         }
233       }
234 
235       /* umspeichern der surf-nodes ins ba system */
236       k=0;
237       for (u=1; u< div_l[0]; u++)
238       {
239         for (v=1; v< div_l[3]; v++)
240         {
241         if ((sb1==0)&&(sa1==3)) { b=u+ offs1            ; a=v                ;}
242         if ((sb1==3)&&(sa1==2)) { b=vmax-v-1 - offs2   ; a=u                  ;}
243         if ((sb1==2)&&(sa1==1)) { b=umax-u-1 - offs2   ; a=vmax-v-1          ;}
244         if ((sb1==1)&&(sa1==0)) { b=v+ offs1            ; a=umax-u-1          ;}
245         if ((sb1==0)&&(sa1==1)) { b=umax-u-1 - offs2   ; a=v                  ;}
246         if ((sb1==3)&&(sa1==0)) { b=v+ offs1            ; a=u                ;}
247         if ((sb1==2)&&(sa1==3)) { b=u+ offs1             ; a=vmax-v-1        ;}
248         if ((sb1==1)&&(sa1==2)) { b=vmax-v-1 - offs2   ; a=umax-u-1          ;}
249         n_ba[b* amax +a]=surf[sur].nod[k]; k++;
250         x_ba[b* amax +a]=x[u* vmax +v];
251         y_ba[b* amax +a]=y[u* vmax +v];
252         z_ba[b* amax +a]=z[u* vmax +v];
253 #if TEST
254   printf(" Fall b:%d a:%d\n", b, a);
255 #endif
256         }
257       }
258 
259       /* umspeichern aller koordinaten ins ba system */
260       for (u=0; u< umax; u++)
261       {
262         for (v=0; v< vmax; v++)
263         {
264         if ((sb1==0)&&(sa1==3)) { b=u                   ; a=v         ;}
265         if ((sb1==3)&&(sa1==2)) { b=vmax-v-1           ; a=u           ;}
266         if ((sb1==2)&&(sa1==1)) { b=umax-u-1           ; a=vmax-v-1   ;}
267         if ((sb1==1)&&(sa1==0)) { b=v                   ; a=umax-u-1   ;}
268         if ((sb1==0)&&(sa1==1)) { b=umax-u-1           ; a=v           ;}
269         if ((sb1==3)&&(sa1==0)) { b=v                   ; a=u         ;}
270         if ((sb1==2)&&(sa1==3)) { b=u                   ; a=vmax-v-1   ;}
271         if ((sb1==1)&&(sa1==2)) { b=vmax-v-1           ; a=umax-u-1   ;}
272         x_ba[b* amax +a]=x[u* vmax +v];
273         y_ba[b* amax +a]=y[u* vmax +v];
274         z_ba[b* amax +a]=z[u* vmax +v];
275 #if TEST
276   printf("u:%d v:%d  x_ba[%d][%d]=%lf\n", u, v, b, a, x_ba[b* amax +a]);
277 #endif
278         }
279       }
280 
281 
282   return(1);
283 }
284 
285 
286 /**********************************************************************************/
287 /* Fuellt ein xyz-feld mit den koordinaten einer Flaeche bei der gegenueber       */
288 /* liegende seiten ungleiche divisions haben.                                     */
289 /* Die erforderlichen divisions muessen vorher mit newDivisions() best. werden.   */
290 /* Die xyz-Koordinaten gelten fuer ein Feld im ba-Raum                            */
291 /*                                                                                */
292 /* in:                                                                            */
293 /* sur      surface-index                                                         */
294 /* div_l    feld mit den divisions der surface-edges                            */
295 /* div_a    ersatzdivision der 'a'-edges der surf.                              */
296 /* div_b    ersatzdivision der 'b'-edges der surf.                              */
297 /* sa1,sa2,sb1,sb2  Zuordnung der original-edges zu den a&b-edges             */
298 /*                                                                                */
299 /* out:                                                                           */
300 /* n_uv        nodeNr im uv-feld, die zusaetzlichen ersatz-stuetzpunkte sind      */
301 /*             nicht mit nodes belegt da sie bei der Vernetzung rausfallen        */
302 /* umax, vmax  anzahl der ersatz-stuetzpunkte in 'u' und 'v' bzw entlang edge   */
303 /*             '0' und '3' ( umax = div_(a|b) +1 )                                */
304 /* n_ba        nodeNr im ba-feld, siehe n_uv                                      */
305 /* offs_sa1    div_a-div_l[sa1], zur elementerzeugung notwendig                   */
306 /* offs_sa2    div_a-div_l[sa2]                                                   */
307 /* x,y,z       f(u,v) aus dem surfmesher, alle u,v positionen sind belegt         */
308 /* x_ba..      f(b,a) aus dem surfmesher, alle b,a positionen sind belegt         */
309 /*                                                                                */
310 /*                                                                                */
311 /**********************************************************************************/
fillSurf_ba2(int sur,int * div_l,int div_a,int div_b,int sa1,int sa2,int sb1,int sb2,int * n_uv,int * umax,int * vmax,int * n_ba,int * offs_sa1,int * offs_sa2,double * x,double * y,double * z,double * x_ba,double * y_ba,double * z_ba)312 int  fillSurf_ba2( int sur, int *div_l, int div_a, int div_b, int sa1, int sa2, int sb1, int sb2, int *n_uv, int *umax, int *vmax, int *n_ba,  int *offs_sa1, int *offs_sa2, double *x, double *y, double *z, double *x_ba, double *y_ba, double *z_ba )
313 {
314   int n,o,m, u,v, b=0,a=0;
315   int nodnr;
316   double *lx, *ly, *lz; /* line koordinates for linelength() */
317   int amax, bmax;
318   int flag;
319 
320   int k;
321 
322       bmax=div_b+1;
323       amax=div_a+1;
324       if ((sa1==0)||(sa1==2))
325       {
326         *umax=amax    ;
327         *vmax=bmax    ;
328       }
329       else
330       {
331         *umax=bmax    ;
332         *vmax=amax    ;
333       }
334       edgeNodes( *vmax, *umax, sur, n_uv );
335 
336       /* die Randknoten sind nun bekannt. es muessen nun ersatzkoordinaten */
337       /* mit dem spacing der ersatzdivissions berechnet werden. dazu wird  */
338       /* in einem feld aus koordinate(x,y oder z) und der lauflaenge s int-*/
339       /* erpoliert. Ausserdem werden die Randknoten im b,a system          */
340       /* gespeichert, dazu ist auch ein offset erforderlich                */
341 
342       *offs_sa1=div_a-div_l[sa1];
343       *offs_sa2=div_a-div_l[sa2];
344 
345       /* side 0 */
346       v=0;
347       n=div_l[0]+1;        /* anzahl von original-nodes auf der line */
348       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
349           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
350           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
351       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
352       for (u=0; u<n; u++)
353       {
354         nodnr=n_uv[u* *vmax +v];
355         o=0;
356         if ((sb1==0)&&(sa1==3)) { b=u                     ; a=0                    ;  o=1 ;}
357         if ((sb1==3)&&(sa1==2)) { b=*vmax-1               ; a=u                    ;  o=2 ;}
358         if ((sb1==2)&&(sa1==1)) { b=*umax-u-1-*offs_sa2   ; a=*vmax-1              ;  o=3 ;}
359         if ((sb1==1)&&(sa1==0)) { b=0                     ; a=*umax-u-1-*offs_sa1  ;  o=4 ;}
360         if ((sb1==0)&&(sa1==1)) { b=*umax-u-1             ; a=0                    ;  o=5 ;}
361         if ((sb1==3)&&(sa1==0)) { b=0                     ; a=u                    ;  o=6 ;}
362         if ((sb1==2)&&(sa1==3)) { b=u+*offs_sa1           ; a=*vmax-1              ;  o=7 ;}
363         if ((sb1==1)&&(sa1==2)) { b=*vmax-1               ; a=*umax-u-1-*offs_sa2  ;  o=8 ;}
364         n_ba[b* amax +a]=nodnr;
365     sem_wait(&sem_n);
366         lx[u]=npre[nodnr].nx;
367         ly[u]=npre[nodnr].ny;
368         lz[u]=npre[nodnr].nz;
369     sem_post(&sem_n);
370       }
371       /* nun lx,ly,lz auf die geaenderte division umrechnen */
372       u=0;
373       flag=0;
374       if( newEdgePositions( n, u,v, *umax,*vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
375       free(lx);free(ly);free(lz);
376 
377       /* side 1 */
378       u=*umax-1;
379       n=div_l[1]+1;
380       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
381           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
382           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
383       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
384       for (v=0; v<n; v++)
385       {
386         nodnr=n_uv[u**vmax +v];
387         o=0;
388         if ((sb1==0)&&(sa1==3)) { b=*umax-1              ; a=v                    ;  o=1 ;}
389         if ((sb1==3)&&(sa1==2)) { b=*vmax-v-1-*offs_sa2   ; a=*umax-1               ;  o=2 ;}
390         if ((sb1==2)&&(sa1==1)) { b=0                   ; a=*vmax-v-1-*offs_sa1    ;  o=3 ;}
391         if ((sb1==1)&&(sa1==0)) { b=v                   ; a=0                    ;  o=4 ;}
392         if ((sb1==0)&&(sa1==1)) { b=0                   ; a=v                    ;  o=5 ;}
393         if ((sb1==3)&&(sa1==0)) { b=v+*offs_sa1          ; a=*umax-1               ;  o=6 ;}
394         if ((sb1==2)&&(sa1==3)) { b=*umax-1              ; a=*vmax-v-1-*offs_sa2    ;  o=7 ;}
395         if ((sb1==1)&&(sa1==2)) { b=*vmax-v-1            ; a=0                    ;  o=8 ;}
396         n_ba[b*amax +a]=nodnr;
397     sem_wait(&sem_n);
398         lx[v]=npre[nodnr].nx;
399         ly[v]=npre[nodnr].ny;
400         lz[v]=npre[nodnr].nz;
401     sem_post(&sem_n);
402       }
403       /* nun auf die geaenderte division umrechnen */
404       v=0;
405       flag=1;
406       if( newEdgePositions( n, u,v, *umax,*vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
407       free(lx);free(ly);free(lz);
408 
409 
410       /* side 2 */
411       v=*vmax-1;
412       n=div_l[2]+1;
413       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
414           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
415           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
416       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
417       m=*umax-n;
418       for (u=*umax-1; u>=m; u--)
419       {
420         nodnr=n_uv[u**vmax +v];
421         o=0;
422         if ((sb1==0)&&(sa1==3)) { b=u-*offs_sa2          ; a=*vmax-1               ;  o=1 ;}
423         if ((sb1==3)&&(sa1==2)) { b=0                   ; a=u-*offs_sa1           ;  o=2 ;}
424         if ((sb1==2)&&(sa1==1)) { b=*umax-u-1            ; a=0                    ;  o=3 ;}
425         if ((sb1==1)&&(sa1==0)) { b=*vmax-1              ; a=*umax-u-1             ;  o=4 ;}
426         if ((sb1==0)&&(sa1==1)) { b=*umax-u-1+*offs_sa1   ; a=*vmax-1               ;  o=5 ;}
427         if ((sb1==3)&&(sa1==0)) { b=*vmax-1              ; a=u-*offs_sa2           ;  o=6 ;}
428         if ((sb1==2)&&(sa1==3)) { b=u                   ; a=0                    ;  o=7 ;}
429         if ((sb1==1)&&(sa1==2)) { b=0                   ; a=*umax-u-1             ;  o=8 ;}
430         n_ba[b*amax +a]=nodnr;
431     sem_wait(&sem_n);
432         lx[u-m]=npre[nodnr].nx;
433         ly[u-m]=npre[nodnr].ny;
434         lz[u-m]=npre[nodnr].nz;
435     sem_post(&sem_n);
436       }
437       /* nun auf die geaenderte division umrechnen */
438       u=0;
439       flag=0;
440       if( newEdgePositions( n, u,v, *umax,*vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
441       free(lx);free(ly);free(lz);
442 
443 
444       /* side 3 */
445       u=0;
446       n=div_l[3]+1;
447       if (((lx = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
448           ((ly = (double *)malloc( (n)*sizeof(double)) ) == NULL )||
449           ((lz = (double *)malloc( (n)*sizeof(double)) ) == NULL ))
450       { errMsg(" ERROR: realloc failure in fillSurf_ba()\n");    return(-1); }
451       m=*vmax-n;
452       for (v=*vmax-1; v>=m; v--)
453       {
454         nodnr=n_uv[u**vmax +v];
455         o=0;
456         if ((sb1==0)&&(sa1==3)) { b=0                   ; a=v-*offs_sa1           ;  o=1 ;}
457         if ((sb1==3)&&(sa1==2)) { b=*vmax-v-1            ; a=0                    ;  o=2 ;}
458         if ((sb1==2)&&(sa1==1)) { b=*umax-1              ; a=*vmax-v-1             ;  o=3 ;}
459         if ((sb1==1)&&(sa1==0)) { b=v-*offs_sa2          ; a=*umax-1               ;  o=4 ;}
460         if ((sb1==0)&&(sa1==1)) { b=*umax-1              ; a=v-*offs_sa2           ;  o=5 ;}
461         if ((sb1==3)&&(sa1==0)) { b=v                   ; a=0                    ;  o=6 ;}
462         if ((sb1==2)&&(sa1==3)) { b=0                   ; a=*vmax-v-1             ;  o=7 ;}
463         if ((sb1==1)&&(sa1==2)) { b=*vmax-v-1+*offs_sa1   ; a=*umax-1               ;  o=8 ;}
464         n_ba[b* amax +a]=nodnr;
465     sem_wait(&sem_n);
466         lx[v-m]=npre[nodnr].nx;
467         ly[v-m]=npre[nodnr].ny;
468         lz[v-m]=npre[nodnr].nz;
469     sem_post(&sem_n);
470       }
471       /* nun auf die geaenderte division umrechnen */
472       v=0;
473       flag=1;
474       if( newEdgePositions( n, u,v, *umax,*vmax, lx,ly,lz, x,y,z, flag) <0) return(-1);
475       free(lx);free(ly);free(lz);
476 
477 
478       k=0;
479       surfMesh( vmax, umax, x, y, z);
480       for (u=1; u< *umax-1; u++)
481       {
482         for (v=1; v< *vmax-1; v++)
483         {
484         /* umspeichern der temp-nodes ins ba system */
485         o=0;
486         if ((sb1==0)&&(sa1==3)) { b=u                   ; a=v                    ;  o=1 ;}
487         if ((sb1==3)&&(sa1==2)) { b=*vmax-v-1           ; a=u                    ;  o=2 ;}
488         if ((sb1==2)&&(sa1==1)) { b=*umax-u-1           ; a=*vmax-v-1            ;  o=3 ;}
489         if ((sb1==1)&&(sa1==0)) { b=v                   ; a=*umax-u-1            ;  o=4 ;}
490         if ((sb1==0)&&(sa1==1)) { b=*umax-u-1           ; a=v                    ;  o=5 ;}
491         if ((sb1==3)&&(sa1==0)) { b=v                   ; a=u                    ;  o=6 ;}
492         if ((sb1==2)&&(sa1==3)) { b=u                   ; a=*vmax-v-1            ;  o=7 ;}
493         if ((sb1==1)&&(sa1==2)) { b=*vmax-v-1           ; a=*umax-u-1            ;  o=8 ;}
494         n_ba[b* amax +a]=surf[sur].nod[k]; k++;
495         x_ba[b* amax +a]=x[u* *vmax +v];
496         y_ba[b* amax +a]=y[u* *vmax +v];
497         z_ba[b* amax +a]=z[u* *vmax +v];
498 #if TEST
499   printf(" Fall:%d b:%d a:%d\n", o, b, a);
500 #endif
501         }
502       }
503       for (u=0; u< *umax; u++)
504       {
505         for (v=0; v< *vmax; v++)
506         {
507         /* umspeichern der koordinaten ins ba system */
508         if ((sb1==0)&&(sa1==3)) { b=u                   ; a=v                    ;  o=1 ;}
509         if ((sb1==3)&&(sa1==2)) { b=*vmax-v-1           ; a=u                    ;  o=2 ;}
510         if ((sb1==2)&&(sa1==1)) { b=*umax-u-1           ; a=*vmax-v-1            ;  o=3 ;}
511         if ((sb1==1)&&(sa1==0)) { b=v                   ; a=*umax-u-1            ;  o=4 ;}
512         if ((sb1==0)&&(sa1==1)) { b=*umax-u-1           ; a=v                    ;  o=5 ;}
513         if ((sb1==3)&&(sa1==0)) { b=v                   ; a=u                    ;  o=6 ;}
514         if ((sb1==2)&&(sa1==3)) { b=u                   ; a=*vmax-v-1            ;  o=7 ;}
515         if ((sb1==1)&&(sa1==2)) { b=*vmax-v-1           ; a=*umax-u-1            ;  o=8 ;}
516         x_ba[b* amax +a]=x[u* *vmax +v];
517         y_ba[b* amax +a]=y[u* *vmax +v];
518         z_ba[b* amax +a]=z[u* *vmax +v];
519 #if TEST
520   printf("u:%d v:%d  x_ba[%d][%d]=%lf\n", u, v, b, a, x_ba[b* amax +a]);
521 #endif
522         }
523       }
524 
525       /* randbereiche umspeichern (nodenr der diagonale den raendern der undefinierten
526          luecken zuordnen) */
527       a=div_l[sa1];
528       for (b=1; b<*offs_sa1; b++)
529       {
530         n_ba[b* amax +a]=n_ba[b* amax +(div_a-b)];
531 #if TEST
532   printf("1 node:%d b:%d a:%d (div_a-b):%d\n", n_ba[b* amax +a], b, a,(div_a-b));
533 #endif
534       }
535       o=0;
536       b=*offs_sa1;
537       for (a=div_l[sa1]+1; a<div_a; a++)
538       {
539         o++;
540         n_ba[b* amax +a]=n_ba[(b-o)* amax +a];
541 #if TEST
542   printf("2 node:%d b:%d a:%d\n", n_ba[b* amax +a], b, a);
543 #endif
544       }
545       o=0;
546       a=div_l[sa2];
547       for (b=div_b-1; b>div_b - *offs_sa2; b--)
548       {
549         o++;
550         n_ba[b* amax +a]=n_ba[b* amax +(div_a-o)];
551 #if TEST
552   printf("3 node:%d b:%d a:%d\n", n_ba[b* amax +a], b, a);
553 #endif
554      }
555       o=0;
556       b=div_b- *offs_sa2;
557       for (a=div_l[sa2]+1; a<div_a; a++)
558       {
559         o++;
560         n_ba[b* amax +a]=n_ba[(b+o)* amax +a];
561 #if TEST
562   printf("4 node:%d b:%d a:%d\n", n_ba[b* amax +a], b, a);
563 #endif
564       }
565 
566   return(1);
567 }
568 
569 
570 
571 
572 /**********************************************************************************/
573 /*                                                                                */
574 /*                                                                                */
575 /*                                                                                */
576 /*                                                                                */
577 /*                                                                                */
578 /*                                                                                */
579 /*                                                                                */
580 /*                                                                                */
581 /**********************************************************************************/
evalBody2(int b_indx)582 int evalBody2( int b_indx )
583 {
584   int i,j=0,n;
585 
586   int  dum1, dum2;
587 
588   int   div_a,div_b, sa1,sa2,sb1,sb2;
589 
590 #if TEST
591   printf("\n unbalanced Body:%s \n\n",body[b_indx].name);
592 #endif
593 
594 
595   /* mastersurf bestimmen */
596   for(i=0; i<body[b_indx].ns; i++)
597   {
598     if (body[b_indx].unbalance[i]) body[b_indx].bs[0]=i;
599 #if TEST1
600     printf(" unbalance[%d]:%d\n", i, body[b_indx].unbalance[i]);
601 #endif
602   }
603 
604   /* new div fuer die Mastersurf */
605   n=newDivisions( &body[b_indx].div_l[body[b_indx].bs[0]][0], &div_a, &div_b, &sa1, &sa2, &sb1, &sb2 );
606   if (n==-1) return(-1);
607   if( body[b_indx].o[body[b_indx].bs[0]]=='-')
608   {
609     dum1=sa1; dum2=sa2;
610     sa1=dum2; sa2=dum1;
611   }
612 
613   /* store the masterlines ml[] */
614   body[b_indx].ml[0]=sb1; body[b_indx].mlt[0]=surf[body[b_indx].s[body[b_indx].bs[0]]].typ[sb1];
615   body[b_indx].ml[1]=sa2; body[b_indx].mlt[1]=surf[body[b_indx].s[body[b_indx].bs[0]]].typ[sa2];
616   body[b_indx].ml[2]=sb2; body[b_indx].mlt[2]=surf[body[b_indx].s[body[b_indx].bs[0]]].typ[sb2];
617   body[b_indx].ml[3]=sa1; body[b_indx].mlt[3]=surf[body[b_indx].s[body[b_indx].bs[0]]].typ[sa1];
618 
619   /* Fuelle ein xyz-feld mit den koordinaten einer Flaeche mit ungleichen divisions. */
620   body[b_indx].s_indx[0]=body[b_indx].s[body[b_indx].bs[0]];
621 #if TEST1
622   for (i=0; i<4; i++)
623     printf ("body[b_indx].ml[%d]:%s\n",i,line[surf[body[b_indx].s[body[b_indx].bs[0]]].l[body[b_indx].ml[i]]].name);
624   printf ("sur0:%s \n", surf[body[b_indx].s_indx[0]].name);
625 #endif
626 
627   body[b_indx].vmax=div_b+1;
628   body[b_indx].umax=div_a+1;
629 
630   /* suchen der surf an masterline body[b_indx].ml[0] zur bestimmung von cmax */
631   body[b_indx].wmax=-1;
632   for (i=0; i<body[b_indx].ns; i++)
633   {
634     n= body[b_indx].s[i];
635     if(i!=body[b_indx].bs[0]) for (j=0; j<surf[n].nl; j++)
636     {
637       if((surf[n].l[j]==surf[body[b_indx].s_indx[0]].l[body[b_indx].ml[0]])&&(surf[n].typ[j]==surf[body[b_indx].s_indx[0]].typ[body[b_indx].ml[0]]))
638       {
639         if (body[b_indx].unbalance[i]!=0)
640 	{
641           errMsg(" ERROR, body %s not meshable, correct div, side:%d (unbal:%d)!\n", body[b_indx].name, i, body[b_indx].unbalance[i]);
642           return(-1);
643         }
644         body[b_indx].bs[1]=i;
645         body[b_indx].s_indx[1]=n;
646 #if TEST1
647         printf ("sur1:%s \n", surf[body[b_indx].s_indx[1]].name);
648 #endif
649         /* bestimme die parametrische kantenlaenge cmax = div von linie davor oder danach */
650         if(j) body[b_indx].wmax= body[b_indx].div_l[body[b_indx].bs[1]][j-1]+1;
651         else  body[b_indx].wmax= body[b_indx].div_l[body[b_indx].bs[1]][1]+1;
652       }
653     }
654   }
655   if(body[b_indx].wmax==-1)
656   { printf(" FATAL ERROR, could not determine cmax:%d, check program-code\n", body[b_indx].wmax); exit(-1); }
657 
658   /* amax, bmax, cmax sind bekannt, damit die Datenfelder dimensionieren */
659 #if TEST1
660   printf ("Nr of Nodes in 3D amax:%d bmax:%d cmax:%d\n", body[b_indx].umax, body[b_indx].vmax, body[b_indx].wmax );
661 #endif
662 
663 
664   return(1);
665 }
666 
667 
668 
fillBody2(int b_indx,int ** pn_abc)669 int fillBody2( int b_indx, int **pn_abc)
670 {
671   int i,j=0,k,n,a,b,c,o;
672   int  buf[4];
673   int *n_uv=NULL, *n_ba=NULL, umax, vmax, offs1, offs2;
674   double  *x=NULL, *y=NULL, *z=NULL, *x_ba=NULL, *y_ba=NULL, *z_ba=NULL, xn,yn,zn;
675 
676   int *n_abc;
677   double  *x_abc=NULL, *y_abc=NULL, *z_abc=NULL;
678 
679   int   div_a,div_b, sa1,sa2,sb1,sb2;
680 
681   int *offs_sa1, *offs_sa2, *div_sa1, *div_sa2;
682   char *mlt;
683   int *amax, *bmax, *cmax, *bs, *ml, *s_indx;
684 
685   amax=&body[b_indx].umax;
686   bmax=&body[b_indx].vmax;
687   cmax=&body[b_indx].wmax;
688   bs=&body[b_indx].bs[0];
689   ml=&body[b_indx].ml[0];
690   mlt=&body[b_indx].mlt[0];
691   s_indx=&body[b_indx].s_indx[0];
692   offs_sa1=&body[b_indx].offs_sa1;
693   offs_sa2=&body[b_indx].offs_sa2;
694   div_sa1=&body[b_indx].div_sa1;
695   div_sa2=&body[b_indx].div_sa2;
696 
697   sb1=ml[0];
698   sa2=ml[1];
699   sb2=ml[2];
700   sa1=ml[3];
701   div_a=*amax-1;
702   div_b=*bmax-1;
703 
704 
705   /* Hilfsfelder fuer die surfs */
706   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
707   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
708     goto noMesh; }
709   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
710   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
711     goto noMesh; }
712   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
713   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
714     goto noMesh; }
715   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
716   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
717     goto noMesh; }
718   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
719   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
720     goto noMesh; }
721   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
722   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
723     goto noMesh; }
724   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
725   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
726     goto noMesh; }
727   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
728   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
729     goto noMesh; }
730 
731   fillSurf_ba2( s_indx[0], &body[b_indx].div_l[bs[0]][0], div_a, div_b, sa1, sa2, sb1, sb2, n_uv, &umax, &vmax, n_ba, offs_sa1, offs_sa2, x,y,z, x_ba,y_ba,z_ba);
732   offs1=*offs_sa1;
733   offs2=*offs_sa2;
734   *div_sa1=body[b_indx].div_l[bs[0]][sa1];
735   *div_sa2=body[b_indx].div_l[bs[0]][sa2];
736 
737   if( (n_abc=(int *)malloc((*amax)*(*bmax)*(*cmax)*sizeof(int)) ) == NULL )
738   { printf(" ERROR: realloc failure in fillBody body can not be meshed\n\n"); goto noMesh; }
739   if( (x_abc=(double *)realloc((double *)x_abc, (*amax)*(*bmax)*(*cmax)*sizeof(double)) ) == NULL )
740   { printf(" ERROR: realloc failure in fillBody body can not be meshed\n\n"); goto noMesh; }
741   if( (y_abc=(double *)realloc((double *)y_abc, (*amax)*(*bmax)*(*cmax)*sizeof(double)) ) == NULL )
742   { printf(" ERROR: realloc failure in fillBody body can not be meshed\n\n"); goto noMesh; }
743   if( (z_abc=(double *)realloc((double *)z_abc, (*amax)*(*bmax)*(*cmax)*sizeof(double)) ) == NULL )
744   { printf(" ERROR: realloc failure in fillBody body can not be meshed\n\n"); goto noMesh; }
745 
746   *pn_abc=n_abc;
747 
748   /* felder initialisieren */
749   for (a=0; a<*amax; a++)
750   {
751     for (b=0; b<*bmax; b++)
752     {
753       for (c=0; c<*cmax; c++)
754       {
755         n_abc[a**bmax**cmax +b**cmax +c]=0;
756         x_abc[a**bmax**cmax +b**cmax +c]=-scale->x;
757         y_abc[a**bmax**cmax +b**cmax +c]=-scale->y;
758         z_abc[a**bmax**cmax +b**cmax +c]=-scale->z;
759       }
760     }
761   }
762 
763   /* Uebertrage die daten der mastersurf: bs[0] bzw s_indx[0] ins abc-sys. */
764   c=0;
765   for (a=0; a<*amax; a++)
766   {
767     for (b=0; b<*bmax; b++)
768     {
769       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[b**amax +a];
770       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[b**amax +a];
771       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[b**amax +a];
772       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[b**amax +a];
773     }
774   }
775 
776 
777 
778   /* Zuordnen der edges von bs[1] zum surf-ba system */
779   /* surf-edge b1 entspricht body-edge c */
780   /* surf-edge a1 entspricht body-edge b */
781   if( body[b_indx].o[bs[1]]=='+')
782   {
783     if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[0])
784     && ( mlt[0]==surf[s_indx[1]].typ[0])) {i=0; sb1=1; sa2=2; sb2=3; sa1=0; }
785     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[1])
786     && ( mlt[0]==surf[s_indx[1]].typ[1])) {i=1;  sb1=2; sa2=3; sb2=0; sa1=1; }
787     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[2])
788     && ( mlt[0]==surf[s_indx[1]].typ[2])) {i=2;  sb1=3; sa2=0; sb2=1; sa1=2; }
789     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[3])
790     && ( mlt[0]==surf[s_indx[1]].typ[3])) { i=3; sb1=0; sa2=1; sb2=2; sa1=3; }
791     else
792       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
793   }
794   else
795   {
796     if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[0])
797     && ( mlt[0]==surf[s_indx[1]].typ[0])) {i=0;  sb1=3; sa2=2; sb2=1; sa1=0; }
798     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[1])
799     && ( mlt[0]==surf[s_indx[1]].typ[1])) {i=1;  sb1=0; sa2=3; sb2=2; sa1=1; }
800     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[2])
801     && ( mlt[0]==surf[s_indx[1]].typ[2])) {i=2;  sb1=1; sa2=0; sb2=3; sa1=2; }
802     else if(( surf[s_indx[0]].l[ml[0]]==surf[s_indx[1]].l[3])
803     && ( mlt[0]==surf[s_indx[1]].typ[3])) {i=3;  sb1=2; sa2=1; sb2=0; sa1=3; }
804     else
805       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
806   }
807   ml[4]=sa2; mlt[4]=surf[body[b_indx].s[bs[1]]].typ[sa2];
808   div_a= *bmax-1;
809   div_b= *cmax-1;
810   offs1=0;
811   offs2=0;
812 
813   /* hilfsspeicher freigeben und neu allocieren */
814   free(n_uv);
815   free(n_ba);
816   free(x);
817   free(y);
818   free(z);
819   free(x_ba);
820   free(y_ba);
821   free(z_ba);
822   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
823   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
824     goto noMesh; }
825   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
826   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
827     goto noMesh; }
828   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
829   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
830     goto noMesh; }
831   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
832   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
833     goto noMesh; }
834   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
835   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
836     goto noMesh; }
837   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
838   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
839     goto noMesh; }
840   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
841   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
842     goto noMesh; }
843   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
844   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
845     goto noMesh; }
846 
847   /* F�lle ein xyz-feld mit den koordinaten einer Flaeche mit gleichen divisions. */
848   fillSurf_ba1( s_indx[1], &body[b_indx].div_l[bs[1]][0], div_a, div_b, sa1, sa2, sb1, sb2,
849        n_uv, n_ba, offs1, offs2, x,y,z, x_ba,y_ba,z_ba);
850 
851   /* Uebertrage die daten der bs[1] ins abc-sys. */
852   a=0;
853   for (b=0; b<*bmax; b++)
854   {
855     for (c=0; c<*cmax; c++)
856     {
857       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[c**bmax +b];
858       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[c**bmax +b];
859       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[c**bmax +b];
860       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[c**bmax +b];
861     }
862   }
863 
864   /* suchen der surf an masterline ml[4], diese liegt der mastersurf gegenueber */
865   /* und muss unbalanced sein */
866   for (i=0; i<body[b_indx].ns; i++)
867   {
868     n= body[b_indx].s[i];
869     if((i!=bs[1])&&(i!=bs[0])) for (j=0; j<surf[n].nl; j++)
870     {
871       if((surf[n].l[j]==surf[s_indx[1]].l[ml[4]])&&(surf[n].typ[j]==surf[s_indx[1]].typ[ml[4]]))
872       {
873         if (body[b_indx].unbalance[i]!=1)
874 	{
875           errMsg(" ERROR, body %s not meshable, correct div, side:%d (unbal:%d)!\n", body[b_indx].name, i, body[b_indx].unbalance[i]);
876           goto noMesh;
877         }
878         bs[2]=i;
879         s_indx[2]=n;
880 #if TEST1
881         printf ("sur2:%s \n", surf[s_indx[2]].name);
882 #endif
883       }
884     }
885   }
886 
887   /* F�lle ein xyz-feld mit den koordinaten einer Flaeche mit ungleichen divisions. */
888   n=newDivisions( &body[b_indx].div_l[bs[2]][0], &div_a, &div_b, &sa1, &sa2, &sb1, &sb2 );
889   if (n==-1) goto noMesh;
890 
891   /* check the corresponding divisions of surf2 with surf0 */
892   /* could be wrong if there are only two different divisions on the 4 edges (ie. 16,16,4,4) */
893   buf[0]=sa1;
894   buf[1]=sb2;
895   buf[2]=sa2;
896   buf[3]=sb1;
897   if( body[b_indx].o[bs[2]]=='+')
898   {
899     if( body[b_indx].div_l[bs[2]][sb1]==body[b_indx].div_l[bs[2]][sa1])
900       if( body[b_indx].div_l[bs[2]][sa1]!= body[b_indx].div_l[bs[0]][ml[1]])
901       { sb1=buf[0]; sa1=buf[1]; sb2=buf[2]; sa2=buf[3]; }
902     if( body[b_indx].div_l[bs[2]][sb1]==body[b_indx].div_l[bs[2]][sa2])
903       if( body[b_indx].div_l[bs[2]][sa2]!= body[b_indx].div_l[bs[0]][ml[3]])
904       { sb1=buf[2]; sa1=buf[3]; sb2=buf[0]; sa2=buf[1]; }
905   }
906   else
907   {
908     if( body[b_indx].div_l[bs[2]][sb1]==body[b_indx].div_l[bs[2]][sa2])
909       if( body[b_indx].div_l[bs[2]][sa1]!= body[b_indx].div_l[bs[0]][ml[3]])
910       { sb1=buf[2]; sa1=buf[3]; sb2=buf[0]; sa2=buf[1]; }
911     if( body[b_indx].div_l[bs[2]][sb1]==body[b_indx].div_l[bs[2]][sa1])
912       if( body[b_indx].div_l[bs[2]][sa1]!= body[b_indx].div_l[bs[0]][ml[3]])
913       { sb1=buf[0]; sa1=buf[1]; sb2=buf[2]; sa2=buf[3]; }
914   }
915 
916   /* hilfsspeicher freigeben und neu allocieren */
917   free(n_uv);
918   free(n_ba);
919   free(x);
920   free(y);
921   free(z);
922   free(x_ba);
923   free(y_ba);
924   free(z_ba);
925   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
926   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
927     goto noMesh; }
928   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
929   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
930     goto noMesh; }
931   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
932   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
933     goto noMesh; }
934   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
935   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
936     goto noMesh; }
937   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
938   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
939     goto noMesh; }
940   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
941   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
942     goto noMesh; }
943   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
944   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
945     goto noMesh; }
946   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
947   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
948     goto noMesh; }
949 
950   fillSurf_ba2( s_indx[2], &body[b_indx].div_l[bs[2]][0], div_a, div_b, sa1, sa2, sb1, sb2, n_uv, &umax, &vmax, n_ba, &offs1, &offs2, x,y,z, x_ba,y_ba,z_ba);
951 
952   /* Uebertrage die daten der surf bs[2] bzw s_indx[2] ins abc-sys. */
953   c=*cmax-1;
954   if( body[b_indx].o[bs[2]]=='+')
955   {
956    for (a=0; a<*amax; a++)
957    {
958     for (b=0; b<*bmax; b++)
959     {
960       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[(*bmax-1-b)**amax +a];
961       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[(*bmax-1-b)**amax +a];
962       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[(*bmax-1-b)**amax +a];
963       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[(*bmax-1-b)**amax +a];
964     }
965    }
966   }
967   else
968   {
969    for (a=0; a<*amax; a++)
970    {
971     for (b=0; b<*bmax; b++)
972     {
973       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[b**amax +a];
974       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[b**amax +a];
975       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[b**amax +a];
976       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[b**amax +a];
977     }
978    }
979   }
980 
981 
982 
983   /* suchen der surf3 an masterline ml[3] */
984   /* und darf nicht unbalanced sein */
985   for (i=0; i<body[b_indx].ns; i++)
986   {
987     n= body[b_indx].s[i];
988     if(i!=bs[0]) for (j=0; j<surf[n].nl; j++)
989     {
990       if((surf[n].l[j]==surf[s_indx[0]].l[ml[3]])&&(surf[n].typ[j]==surf[s_indx[0]].typ[ml[3]]))
991       {
992         if (body[b_indx].unbalance[i]==1)
993 	{
994           errMsg(" ERROR, body %s not meshable, correct div, side:%d (unbal:%d)!\n", body[b_indx].name, i, body[b_indx].unbalance[i]);
995           goto noMesh;
996         }
997         bs[3]=i;
998         s_indx[3]=n;
999 #if TEST1
1000         printf ("sur3:%s \n", surf[s_indx[3]].name);
1001 #endif
1002       }
1003     }
1004   }
1005 
1006   /* Zuordnen der edges von bs[3] zum surf-ba system */
1007   /* surf-edge b1 entspricht body-edge a */
1008   /* surf-edge a1 entspricht body-edge c */
1009   if( body[b_indx].o[bs[3]]=='+')
1010   {
1011     if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[1])
1012     && ( mlt[3]==surf[s_indx[3]].typ[1])) { sb1=1; sa2=2; sb2=3; sa1=0; }
1013     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[2])
1014     && ( mlt[3]==surf[s_indx[3]].typ[2])) { sb1=2; sa2=3; sb2=0; sa1=1; }
1015     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[3])
1016     && ( mlt[3]==surf[s_indx[3]].typ[3])) { sb1=3; sa2=0; sb2=1; sa1=2; }
1017     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[0])
1018     && ( mlt[3]==surf[s_indx[3]].typ[0])) { sb1=0; sa2=1; sb2=2; sa1=3; }
1019     else
1020       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1021   }
1022   else
1023   {
1024     if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[3])
1025     && ( mlt[3]==surf[s_indx[3]].typ[3])) { sb1=3; sa2=2; sb2=1; sa1=0; }
1026     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[0])
1027     && ( mlt[3]==surf[s_indx[3]].typ[0])) { sb1=0; sa2=3; sb2=2; sa1=1; }
1028     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[1])
1029     && ( mlt[3]==surf[s_indx[3]].typ[1])) { sb1=1; sa2=0; sb2=3; sa1=2; }
1030     else if(( surf[s_indx[0]].l[ml[3]]==surf[s_indx[3]].l[2])
1031     && ( mlt[3]==surf[s_indx[3]].typ[2])) { sb1=2; sa2=1; sb2=0; sa1=3; }
1032     else
1033       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1034   }
1035   div_a= *cmax-1;
1036   div_b= *amax-1;
1037   offs1=0;
1038   offs2=*offs_sa1;
1039 
1040   /* hilfsspeicher freigeben und neu allocieren */
1041   free(n_uv);
1042   free(n_ba);
1043   free(x);
1044   free(y);
1045   free(z);
1046   free(x_ba);
1047   free(y_ba);
1048   free(z_ba);
1049   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1050   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1051     goto noMesh; }
1052   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1053   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1054     goto noMesh; }
1055   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1056   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1057     goto noMesh; }
1058   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1059   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1060     goto noMesh; }
1061   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1062   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1063     goto noMesh; }
1064   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1065   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1066     goto noMesh; }
1067   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1068   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1069     goto noMesh; }
1070   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1071   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1072     goto noMesh; }
1073   /* F�lle ein xyz-feld mit den koordinaten einer Flaeche mit gleichen divisions. */
1074   fillSurf_ba1( s_indx[3], &body[b_indx].div_l[bs[3]][0], div_a, div_b, sa1, sa2, sb1, sb2,
1075        n_uv, n_ba, offs1, offs2, x,y,z, x_ba,y_ba,z_ba);
1076 
1077   /* Uebertrage die daten der surf: bs[3] bzw s_indx[3] ins abc-sys. */
1078   b=0;
1079   for (a=0; a<*amax; a++)
1080   {
1081     for (c=0; c<*cmax; c++)
1082     {
1083       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[a**cmax +c];
1084       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[a**cmax +c];
1085       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[a**cmax +c];
1086       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[a**cmax +c];
1087     }
1088   }
1089 
1090 
1091 
1092   /* suchen der surf4 an masterline ml[1] */
1093   /* und darf nicht unbalanced sein */
1094   for (i=0; i<body[b_indx].ns; i++)
1095   {
1096     n= body[b_indx].s[i];
1097     if(i!=bs[0]) for (j=0; j<surf[n].nl; j++)
1098     {
1099       if((surf[n].l[j]==surf[s_indx[0]].l[ml[1]])&&(surf[n].typ[j]==surf[s_indx[0]].typ[ml[1]]))
1100       {
1101         if (body[b_indx].unbalance[i]==1)
1102 	{
1103           errMsg(" ERROR, body %s not meshable, correct div, side:%d (unbal:%d)!\n", body[b_indx].name, i, body[b_indx].unbalance[i]);
1104           goto noMesh;
1105         }
1106         bs[4]=i;
1107         s_indx[4]=n;
1108 #if TEST1
1109         printf ("sur4:%s \n", surf[s_indx[4]].name);
1110 #endif
1111       }
1112     }
1113   }
1114 
1115   /* Zuordnen der edges von bs[4] zum surf-ba system */
1116   /* surf-edge b1 entspricht body-edge a */
1117   /* surf-edge a1 entspricht body-edge c */
1118   if( body[b_indx].o[bs[4]]=='+')
1119   {
1120     if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[3])
1121     && ( mlt[1]==surf[s_indx[4]].typ[3])) { sb1=3; sa2=2; sb2=1; sa1=0; }
1122     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[0])
1123     && ( mlt[1]==surf[s_indx[4]].typ[0])) { sb1=0; sa2=3; sb2=2; sa1=1; }
1124     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[1])
1125     && ( mlt[1]==surf[s_indx[4]].typ[1])) { sb1=1; sa2=0; sb2=3; sa1=2; }
1126     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[2])
1127     && ( mlt[1]==surf[s_indx[4]].typ[2])) { sb1=2; sa2=1; sb2=0; sa1=3; }
1128     else
1129       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1130   }
1131   else
1132   {
1133     if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[1])
1134     && ( mlt[1]==surf[s_indx[4]].typ[1])) { sb1=1; sa2=2; sb2=3; sa1=0; }
1135     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[2])
1136     && ( mlt[1]==surf[s_indx[4]].typ[2])) { sb1=2; sa2=3; sb2=0; sa1=1; }
1137     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[3])
1138     && ( mlt[1]==surf[s_indx[4]].typ[3])){ sb1=3; sa2=0; sb2=1; sa1=2; }
1139     else if(( surf[s_indx[0]].l[ml[1]]==surf[s_indx[4]].l[0])
1140     && ( mlt[1]==surf[s_indx[4]].typ[0])) { sb1=0; sa2=1; sb2=2; sa1=3; }
1141     else
1142       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1143   }
1144   div_a= *cmax-1;
1145   div_b= *amax-1;
1146   offs1=0;
1147   offs2=*offs_sa2;
1148 
1149   /* hilfsspeicher freigeben und neu allocieren */
1150   free(n_uv);
1151   free(n_ba);
1152   free(x);
1153   free(y);
1154   free(z);
1155   free(x_ba);
1156   free(y_ba);
1157   free(z_ba);
1158   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1159   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1160     goto noMesh; }
1161   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1162   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1163     goto noMesh; }
1164   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1165   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1166     goto noMesh; }
1167   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1168   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1169     goto noMesh; }
1170   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1171   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1172     goto noMesh; }
1173   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1174   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1175     goto noMesh; }
1176   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1177   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1178     goto noMesh; }
1179   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1180   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1181     goto noMesh; }
1182   /* F�lle ein xyz-feld mit den koordinaten einer Flaeche mit gleichen divisions. */
1183   fillSurf_ba1( s_indx[4], &body[b_indx].div_l[bs[4]][0], div_a, div_b, sa1, sa2, sb1, sb2,
1184        n_uv, n_ba, offs1, offs2, x,y,z, x_ba,y_ba,z_ba);
1185 
1186   /* Uebertrage die daten der surf: bs[4] bzw s_indx[4] ins abc-sys. */
1187   b= *bmax-1;
1188   for (a=0; a<*amax; a++)
1189   {
1190     for (c=0; c<*cmax; c++)
1191     {
1192       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[a**cmax +c];
1193       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[a**cmax +c];
1194       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[a**cmax +c];
1195       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[a**cmax +c];
1196     }
1197   }
1198 
1199 
1200 
1201   /* suchen der surf5 an masterline ml[2] */
1202   /* und darf nicht unbalanced sein */
1203   for (i=0; i<body[b_indx].ns; i++)
1204   {
1205     n= body[b_indx].s[i];
1206     if(i!=bs[0]) for (j=0; j<surf[n].nl; j++)
1207     {
1208       if((surf[n].l[j]==surf[s_indx[0]].l[ml[2]])&&(surf[n].typ[j]==surf[s_indx[0]].typ[ml[2]]))
1209       {
1210         if (body[b_indx].unbalance[i]==1)
1211 	{
1212           errMsg(" ERROR, body %s not meshable, correct div, side:%d (unbal:%d)!\n", body[b_indx].name, i, body[b_indx].unbalance[i]);
1213           goto noMesh;
1214         }
1215         bs[5]=i;
1216         s_indx[5]=n;
1217 #if TEST1
1218         printf ("sur5:%s \n", surf[s_indx[5]].name);
1219 #endif
1220       }
1221     }
1222   }
1223 
1224   /* Zuordnen der edges von bs[4] zum surf-ba system */
1225   /* surf-edge b1 entspricht body-edge c */
1226   /* surf-edge a1 entspricht body-edge a */
1227   if( body[b_indx].o[bs[5]]=='+')
1228   {
1229     if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[1])
1230     && ( mlt[2]==surf[s_indx[5]].typ[1])) { sb1=1; sa2=2; sb2=3; sa1=0; }
1231     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[2])
1232     && ( mlt[2]==surf[s_indx[5]].typ[2])) { sb1=2; sa2=3; sb2=0; sa1=1; }
1233     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[3])
1234     && ( mlt[2]==surf[s_indx[5]].typ[3])) { sb1=3; sa2=0; sb2=1; sa1=2; }
1235     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[0])
1236     && ( mlt[2]==surf[s_indx[5]].typ[0])) { sb1=0; sa2=1; sb2=2; sa1=3; }
1237     else
1238       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1239   }
1240   else
1241   {
1242     if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[3])
1243     && ( mlt[2]==surf[s_indx[5]].typ[3])) { sb1=3; sa2=2; sb2=1; sa1=0; }
1244     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[0])
1245     && ( mlt[2]==surf[s_indx[5]].typ[0])) { sb1=0; sa2=3; sb2=2; sa1=1; }
1246     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[1])
1247     && ( mlt[2]==surf[s_indx[5]].typ[1])) { sb1=1; sa2=0; sb2=3; sa1=2; }
1248     else if(( surf[s_indx[0]].l[ml[2]]==surf[s_indx[5]].l[2])
1249     && ( mlt[2]==surf[s_indx[5]].typ[2])) { sb1=2; sa2=1; sb2=0; sa1=3; }
1250     else
1251       { printf(" FATAL ERROR, found no edge\n"); exit(-1); }
1252   }
1253   div_a= *cmax-1;
1254   div_b= *bmax-1;
1255   offs1= *offs_sa1;
1256   offs2= *offs_sa2;
1257 
1258   /* hilfsspeicher freigeben und neu allocieren */
1259   free(n_uv);
1260   free(n_ba);
1261   free(x);
1262   free(y);
1263   free(z);
1264   free(x_ba);
1265   free(y_ba);
1266   free(z_ba);
1267   if( (n_uv=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1268   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1269     goto noMesh; }
1270   if( (n_ba=(int *)malloc( (div_a+1)*(div_b+1)*sizeof(int) ) )==NULL)
1271   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1272     goto noMesh; }
1273   if( (x=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1274   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1275     goto noMesh; }
1276   if( (y=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1277   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1278     goto noMesh; }
1279   if( (z=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1280   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1281     goto noMesh; }
1282   if( (x_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1283   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1284     goto noMesh; }
1285   if( (y_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1286   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1287     goto noMesh; }
1288   if( (z_ba=(double *)malloc( (div_a+1)*(div_b+1)*sizeof(double) ) )==NULL)
1289   { printf(" ERROR: realloc failure, surf:%s can not be meshed\n\n", surf[j].name);
1290     goto noMesh; }
1291   /* F�lle ein xyz-feld mit den koordinaten einer Flaeche mit gleichen divisions. */
1292   fillSurf_ba1( s_indx[5], &body[b_indx].div_l[bs[5]][0], div_a, div_b, sa1, sa2, sb1, sb2,
1293        n_uv, n_ba, offs1, offs2, x,y,z, x_ba,y_ba,z_ba);
1294 
1295   /* Uebertrage die daten der surf: bs[4] bzw s_indx[4] ins abc-sys. */
1296   a= *amax-1;
1297   for (b=0; b<*bmax; b++)
1298   {
1299     for (c=0; c<*cmax; c++)
1300     {
1301       n_abc[a**bmax**cmax +b**cmax +c]=n_ba[b**cmax +c];
1302       x_abc[a**bmax**cmax +b**cmax +c]=x_ba[b**cmax +c];
1303       y_abc[a**bmax**cmax +b**cmax +c]=y_ba[b**cmax +c];
1304       z_abc[a**bmax**cmax +b**cmax +c]=z_ba[b**cmax +c];
1305     }
1306   }
1307   free(n_uv);
1308   free(n_ba);
1309   free(x);
1310   free(y);
1311   free(z);
1312   free(x_ba);
1313   free(y_ba);
1314   free(z_ba);
1315 
1316 
1317 
1318   /* allocate memory for embeded nodes */
1319   if((body[b_indx].nod=(int *)realloc((int *)body[b_indx].nod,((*amax-2)*(*bmax-2)*(*cmax-2))*sizeof(int)))==NULL)
1320   { printf(" ERROR: realloc failure in meshBodies body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
1321 
1322   /* auff�llen des bodies mit nodes */
1323   bodyMesh2( cmax, bmax, amax, x_abc, y_abc, z_abc);
1324 
1325   k=0;
1326   for (a=1; a<*amax-1; a++)
1327   {
1328     for (b=1; b<*bmax-1; b++)
1329     {
1330       for (c=1; c<*cmax-1; c++)
1331       {
1332       xn=x_abc[a**bmax**cmax +b**cmax +c];
1333       yn=y_abc[a**bmax**cmax +b**cmax +c];
1334       zn=z_abc[a**bmax**cmax +b**cmax +c];
1335     sem_wait(&sem_n);
1336       nod(  apre, &npre, 0, apre->nmax+1, xn, yn, zn, 0 );
1337       body[b_indx].nod[k]=n_abc[a**bmax**cmax +b**cmax +c]=apre->nmax;
1338     sem_post(&sem_n);
1339       k++;
1340       }
1341     }
1342   }
1343   body[b_indx].nn=k;
1344 
1345   /* durch die offsets beschriebene randbereiche umspeichern */
1346   /* (nodenr der diagonale den raendern der undefinierten luecken zuordnen) */
1347 
1348   div_a=*amax-1;
1349   div_b=*bmax-1;
1350 #if TEST1
1351   printf(" div_a:%d div_b:%d  div_sa1:%d div_sa2:%d off1:%d off2:%d\n", div_a,div_b,*div_sa1,*div_sa2,*offs_sa1, *offs_sa2);
1352 #endif
1353   for (c=1; c<*cmax-1; c++)
1354   {
1355       a=*div_sa1;
1356       for (b=1; b<*offs_sa1; b++)
1357       {
1358         n_abc[a**bmax**cmax +b**cmax +c]=n_abc[(div_a-b)**bmax**cmax +b**cmax +c];
1359 #if TEST
1360   printf("1 n(%d,%d,%d):%d -> n(%d,%d,%d):%d\n", a,b,c, n_abc[a**bmax**cmax +b**cmax +c],a,b,c, n_abc[(div_a-b)**bmax**cmax +b**cmax +c]);
1361 #endif
1362       }
1363       o=0;
1364       b=*offs_sa1;
1365       for (a=*div_sa1+1; a<div_a; a++)
1366       {
1367         o++;
1368         n_abc[a**bmax**cmax +b**cmax +c]=n_abc[a**bmax**cmax +(b-o)**cmax +c];
1369 #if TEST
1370   printf("2 n(%d,%d,%d):%d -> n(%d,%d,%d):%d\n", a,b,c, n_abc[a**bmax**cmax +b**cmax +c],a,b,c,n_abc[a**bmax**cmax +(b-o)**cmax +c] );
1371 #endif
1372       }
1373       o=0;
1374       a=*div_sa2;
1375       for (b=div_b-1; b>div_b - *offs_sa2; b--)
1376       {
1377         o++;
1378         n_abc[a**bmax**cmax +b**cmax +c]=n_abc[(div_a-o)**bmax**cmax +b**cmax +c];
1379 #if TEST
1380   printf("3 n(%d,%d,%d):%d -> n(%d,%d,%d):%d\n", a,b,c, n_abc[a**bmax**cmax +b**cmax +c],a,b,c,n_abc[(div_a-o)**bmax**cmax +b**cmax +c]);
1381 #endif
1382      }
1383       o=0;
1384       b=div_b- *offs_sa2;
1385       for (a=*div_sa2+1; a<div_a; a++)
1386       {
1387         o++;
1388         n_abc[a**bmax**cmax +b**cmax +c]=n_abc[a**bmax**cmax +(b+o)**cmax +c];
1389 #if TEST
1390   printf("4 n(%d,%d,%d):%d -> n(%d,%d,%d):%d\n", a,b,c, n_abc[a**bmax**cmax +b**cmax +c],a,b,c,n_abc[a**bmax**cmax +(b+o)**cmax +c] );
1391 #endif
1392       }
1393   }
1394 
1395 
1396 
1397 #if TEST
1398   /* darstellen der ergebnisse */
1399   for (a=0; a<*amax; a++)
1400   {
1401    for (b=0; b<*bmax; b++)
1402    {
1403     for (c=0; c<*cmax; c++)
1404     {
1405       printf ("n(%d,%d,%d):%d %lf %lf %lf \n", a,b,c, n_abc[a**bmax**cmax +b**cmax +c], x_abc[a**bmax**cmax +b**cmax +c]* scale->w+scale->x, y_abc[a**bmax**cmax +b**cmax +c]* scale->w+scale->y, z_abc[a**bmax**cmax +b**cmax +c]* scale->w+scale->z);
1406     }
1407    }
1408   }
1409 #endif
1410   free(x_abc);
1411   free(y_abc);
1412   free(z_abc);
1413 
1414   body[b_indx].fail=0;
1415   return(1);
1416  noMesh:;
1417   free(n_uv);
1418   free(n_ba);
1419   free(x);
1420   free(y);
1421   free(z);
1422   free(x_ba);
1423   free(y_ba);
1424   free(z_ba);
1425   free(x_abc);
1426   free(y_abc);
1427   free(z_abc);
1428   free(n_abc);
1429   body[b_indx].fail=1;
1430   return(-1);
1431 }
1432