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 /* TO DO */
24 /* */
25 /* -mittelknoten bei quadratischen elementen koennen aussermittig liegen */
26 /* insbesondere bei nurbs-proj. verschiebung auf kreisbogen ist notwendig. */
27 /* */
28 /* -5-Seitige Bodies sollten noch nicht vernetzbar sein, da die surfnodes von surf2 noch */
29 /* nicht entsprechend den geaenderten u,v koordinaten umsortiert werden, wenn diese neu */
30 /* angelegt werden musste, siehe Zeile: */
31 /* for(j=0; j<surf[ss[1]].nn; j++) surf[ss[1]].nod[j]=surf[s].nod[j]; */
32 /* sie sind nur dank des meshimprovers ok. Aber unter gewissen umstaenden reicht das nicht */
33 /* */
34 /* -7 sided bodies: bodyFrom7Surfs hier wird unter umstaenden noch nicht immer geprueft ob */
35 /* ein linienindex wirkich einer linie oder einer lcmb zugeordnet werden muss. Die variable */
36 /* lm2[] ist hier verdaechtig */
37
38 /* BUGS:
39 int meshPoints( int setNr, int renderFlag )
40 // the threading is temporarely deactivated. Crashes happened and the reason is unclear
41 //printf("thread:%d points\n",i);
42 if( (int)thread_genNodeFromPoint((void *)targ[i].vargp) <0) meshflag=-1;
43 //pthread_create(&tid[i],NULL,thread_genNodeFromPoint,(void *)targ[i].vargp);
44 */
45
46 #include <cgx.h>
47
48 #define MIN_LINELENGTH 1e-9
49 #define INTERPOL_MODE 0
50
51 #define TEST 0
52 #define TEST1 0
53 #define TEST2 0
54
55
56
57 extern double gtol;
58
59 extern char printFlag; /* printf 1:on 0:off */
60 extern char buffer[MAX_LINE_LENGTH];
61
62 FILE *handle; /* for debugging */
63
64 char namebuf[MAX_LINE_LENGTH];
65
66 extern Scale scale[1];
67 extern Summen anz[1];
68 extern Nodes *node;
69 extern Elements *e_enqire;
70 extern NodeBlocks *nBlock;
71 extern Datasets *lcase;
72
73 extern Alias *alias;
74 extern Sets *set;
75 extern Points *point;
76 extern Lines *line;
77 extern Lcmb *lcmb;
78 extern Gsur *surf;
79 extern Gbod *body;
80 extern Nurbs *nurbs;
81 extern Shapes *shape;
82 extern SumGeo anzGeo[1];
83
84 /* additional entities from setFunktions */
85 extern SpecialSet specialset[1];
86 extern int set_nomesh, set_glur, set_blr;
87 extern int setall; /* setNr of the default set "all" */
88
89 /* preliminary nodes, they will be deleded after the elements are created */
90 Summen apre[1];
91 Nodes *npre=NULL;
92
93 /* for CFD-meshing */
94 /* relation of node generated on entity to final node of the mesh, nbuf[npre][nr]=node */
95 /* for cfd more than one node of the mesh can exist based on one node of a certain entity */
96 int **nbuf=NULL;
97 int sum_nbuf=0;
98 int anz_cfdSurfs=0;
99 int writeCFDflag=0;
100 int nurbsflag=0, meshopt_length, meshopt_angle, oldmeshflag;
101
102 extern sem_t sem_n;
103 extern sem_t sem_g;
104 int glob_meshsur=0, glob_repsur=0;
105
106
107
thread_genNodeFromPoint(void * vargp)108 void *thread_genNodeFromPoint(void *vargp)
109 {
110 int i,j;
111 int setNr;
112 int *param;
113 param=(int *)vargp;
114 setNr=param[0];
115 for (i=param[1]; i<param[2]; i++)
116 {
117 j=set[setNr].pnt[i];
118 // sem_g not needed since no point can be created as long as this threads run
119 if ((point[j].nod = (int *)realloc( (int *)point[j].nod, ((int)1)*sizeof(int)) ) == NULL )
120 { printf(" ERROR: realloc failure in meshPoins point:%s can not be meshed\n\n", point[j].name); param[4]=-1; return((void *)-1); }
121
122 sem_wait(&sem_n);
123 nod( apre, &npre, 0, apre->nmax+1, point[j].px, point[j].py, point[j].pz, 0 );
124 point[j].nod[0]=apre->nmax;
125 if(printFlag) printf (" tid:%d meshing point:%s node:%d\n", param[3], point[j].name, apre->nmax);
126 sem_post(&sem_n);
127
128 point[j].nn=1;
129 }
130 return((void *)1);
131 }
132
133
134
meshPoints(int setNr,int renderFlag)135 int meshPoints( int setNr, int renderFlag )
136 {
137 int i;
138 int meshflag;
139
140 typedef struct {
141 int vargp[5];
142 } Threadargs;
143 Threadargs *targ=NULL;
144 pthread_t *tid=NULL;
145 int nlocalThreads;
146
147 /* are elements requested? */
148 if (renderFlag) meshflag=1;
149 else
150 {
151 meshflag=0;
152 for (i=0; i<set[setNr].anz_l; i++)
153 {
154 if(( line[set[setNr].line[i]].etyp==11)||( line[set[setNr].line[i]].etyp==12)) { meshflag=1; break; }
155 }
156 for (i=0; i<set[setNr].anz_s; i++)
157 {
158 if(( surf[set[setNr].surf[i]].etyp==7)||
159 ( surf[set[setNr].surf[i]].etyp==8)||
160 ( surf[set[setNr].surf[i]].etyp==9)||
161 ( surf[set[setNr].surf[i]].etyp==10)) { meshflag=1; break; }
162 }
163 for (i=0; i<set[setNr].anz_b; i++)
164 {
165 if(( body[set[setNr].body[i]].etyp==1)||( body[set[setNr].body[i]].etyp==4)) { meshflag=1; break; }
166 }
167 }
168 if (!meshflag) return(-1);
169
170 if(anz->threads>set[setNr].anz_p) { nlocalThreads=set[setNr].anz_p; }
171 else nlocalThreads=anz->threads;
172 if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
173 if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
174 for(i=0; i<nlocalThreads; i++)
175 {
176 targ[i].vargp[0]=setNr;
177 targ[i].vargp[1]=i* set[setNr].anz_p/nlocalThreads;
178 if((i+1)==nlocalThreads) targ[i].vargp[2]=set[setNr].anz_p;
179 else targ[i].vargp[2]=(i+1)* set[setNr].anz_p/nlocalThreads;
180 targ[i].vargp[3]=i;
181 targ[i].vargp[4]=1; // error indicator (err:-1)
182 // the threading is temporarely deactivated. Crashes happened and the reason is unclear
183 //printf("thread:%d points\n",i);
184 if( (int)thread_genNodeFromPoint((void *)targ[i].vargp) <0) meshflag=-1;
185 //pthread_create(&tid[i],NULL,thread_genNodeFromPoint,(void *)targ[i].vargp);
186 }
187 /*
188 for(i=0; i<nlocalThreads; i++)
189 {
190 pthread_join(tid[i], NULL);
191 if(targ[i].vargp[4] <0) meshflag=-1;
192 }
193 */
194 free(tid); tid=NULL;
195 free(targ); targ=NULL;
196
197 return(meshflag);
198 }
199
200
201
straightNodes(int j,int k,int div,double * pn)202 int straightNodes( int j, int k, int div, double *pn )
203 /* gives node-positions on a straight line due to line-div */
204 /* j: line-index, k: nodenr (starts with 0), pn[3]: x,y,z */
205 {
206 int i;
207 static int curk=100, curj=-1, curdiv=-1;
208 static double p1[3], p2[3], p1p2[3], ep1p2[3], lp1p2;
209 static double l, p1pn[3], *dl=NULL, sum_l;
210 /* printf("j:%d k:%d curj:%d %d\n",j,k,curj,curk); */
211 if(( j!=curj)||( k<=curk)||(div!=curdiv))
212 {
213 if( (dl = (double *)realloc( (double *)dl, div*sizeof(double))) == NULL )
214 { printf(" ERROR: realloc failure in straightNodes()\n\n"); return(-1); }
215
216 curj=j;
217 curdiv=div;
218 p1[0]=point[line[j].p1].px;
219 p1[1]=point[line[j].p1].py;
220 p1[2]=point[line[j].p1].pz;
221 p2[0]=point[line[j].p2].px;
222 p2[1]=point[line[j].p2].py;
223 p2[2]=point[line[j].p2].pz;
224 v_result( p1, p2, p1p2 );
225 lp1p2=v_betrag( p1p2 );
226 v_norm( p1p2, ep1p2 );
227
228 /* berechnung der elementgroessen */
229 dl[0]=l=sum_l=1.;
230 for(i=1; i<div; i++)
231 {
232 l= l*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
233 sum_l+=l; /* Summe aller relativen Elementgroessen */
234 dl[i]= sum_l;
235 /* printf("i:%d l:%lf suml:%lf\n", i, l, sum_l); */
236 }
237 for(i=0; i<div; i++)
238 {
239 dl[i]= dl[i]/sum_l* lp1p2; /* Summe aller Elementgroessen */
240 /* printf("i:%d dl:%lf\n", i,dl[i]); */
241 }
242 }
243 curk=k;
244
245 /* calculate the node-pos. */
246 if (lp1p2==0.)
247 {
248 pn[0]=p1[0]; pn[1]=p1[1]; pn[2]=p1[2];
249 }
250 else
251 {
252 v_scal(&dl[k], ep1p2, p1pn );
253 v_add( p1, p1pn, pn );
254 /* printf("pn:%f %f %f\n",pn[0],pn[1],pn[2]); */
255 }
256 return(1);
257 }
258
259
260
arcNodes(int j,int k,int div,double * pn)261 int arcNodes( int j, int k, int div, double *pn )
262 /* gives node-positions on an arc line due to line-div */
263 /* j: line-index, k: nodenr (starts with 0), pn[3]: x,y,z */
264 {
265 int i;
266 static int curk=100, curj=-1, curdiv=-1;
267 static double p1[3], p2[3], pc[3];
268 static double p1p2[3], ep1p2[3], lp1p2;
269 static double pcp1[3], lpcp1;
270 static double pcp2[3], lpcp2;
271 static double pcpn[3], Tp1p2[3], pcT[3], epcT[3];
272 static double rad, alfa, beta, *dalfa=NULL, T;
273 double rad_cur, l, sum_l;
274
275 /*
276 printf("p1: %lf %lf %lf\n", point[line[j].p1].px,point[line[j].p1].py,point[line[j].p1].pz);
277 printf("p2: %lf %lf %lf\n", point[line[j].p2].px,point[line[j].p2].py,point[line[j].p2].pz);
278 printf("pc: %lf %lf %lf\n", point[line[j].trk].px,point[line[j].trk].py,point[line[j].trk].pz);
279 printf("line-index j:%d k:%d div:%d curk:%d curj:%d\n",j,k,div,curk,curj);
280 */
281 if(( j!=curj)||( k<=curk)||( div!=curdiv))
282 {
283 if( (dalfa = (double *)realloc( (double *)dalfa, div*sizeof(double))) == NULL )
284 { printf(" ERROR: realloc failure in arcNodes()\n\n"); return(-1); }
285
286 curj=j;
287 curdiv=div;
288 p1[0]=point[line[j].p1].px;
289 p1[1]=point[line[j].p1].py;
290 p1[2]=point[line[j].p1].pz;
291 p2[0]=point[line[j].p2].px;
292 p2[1]=point[line[j].p2].py;
293 p2[2]=point[line[j].p2].pz;
294 pc[0]=point[line[j].trk].px;
295 pc[1]=point[line[j].trk].py;
296 pc[2]=point[line[j].trk].pz;
297
298 v_result( p1, p2, p1p2 );
299 v_result( pc, p1, pcp1 );
300 v_result( pc, p2, pcp2 );
301
302 lp1p2=v_betrag( p1p2 );
303 lpcp1=v_betrag( pcp1 );
304 lpcp2=v_betrag( pcp2 );
305 if ((lp1p2==0.)||(lpcp1==0.)||(lpcp2==0.))
306 {
307 pn[0]=point[line[j].p1].px;
308 pn[1]=point[line[j].p1].py;
309 pn[2]=point[line[j].p1].pz;
310 return(1);
311 }
312 rad=(lpcp1+lpcp2)/2.;
313 alfa=asin( (lp1p2/2.)/rad ) *2.;
314 beta=(PI-alfa)/2.;
315
316 /* berechnung der elementgroessen */
317 dalfa[0]=l=sum_l=1.;
318 for(i=1; i<div; i++)
319 {
320 l= l*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
321 sum_l+=l; /* Summe aller relativen Elementgroessen */
322 dalfa[i]= sum_l;
323 // printf("i:%d l:%lf suml:%lf\n", i, l, sum_l);
324 }
325 for(i=0; i<div; i++)
326 {
327 dalfa[i]= dalfa[i]/sum_l * alfa; /* Summe aller Elementgroessen */
328 // printf("i:%d dalfa:%lf\n", i,dalfa[i]);
329 }
330 }
331 curk=k;
332
333 if ((lp1p2==0.)||(lpcp1==0.)||(lpcp2==0.))
334 {
335 pn[0]=point[line[j].p1].px;
336 pn[1]=point[line[j].p1].py;
337 pn[2]=point[line[j].p1].pz;
338 return(1);
339 }
340
341 T=rad/( cos(dalfa[k])/sin(dalfa[k])*sin(beta) + cos(beta) );
342 v_norm( p1p2, ep1p2 );
343 v_scal(&T, ep1p2, Tp1p2 );
344
345 v_add( pcp1, Tp1p2, pcT );
346 v_norm( pcT, epcT );
347
348 rad_cur=(lpcp1*(double)(div-(k+1))/(double)div) + (lpcp2*((double)(k+1)/(double)div));
349 v_scal(&rad_cur, epcT, pcpn );
350
351 v_add( pc, pcpn, pn );
352
353 // printf("r:%lf r(k/d:%d/%d):%lf a:%lf da:%lf b:%lf T:%lf lp1p2:%lf lpcp1:%lf lpcp2:%lf \n", rad,k,div,rad_cur,alfa,dalfa[k],beta,T,lp1p2,lpcp1,lpcp2);
354
355 return(1);
356 }
357
358
359
splineNodes(int j,int k,int div,double * pn)360 int splineNodes( int j, int k, int div, double *pn )
361 /* gives node-positions on an seq-line (spline) due to line-div */
362 /* j: line-index, k: nodenr (starts with 0), pn[3]: x,y,z */
363 {
364 int i, lp[2], iopt=0;
365 static int setNr, curdiv=-1, curn=-1, curj=-1, n, mode;
366 static double lmax, le, *dl=NULL, sum_l, *l=NULL, *x=NULL, *y=NULL, *z=NULL;
367 static double p1[3], p2[3], p1p2[3], lp1p2;
368 static double dl1, lsegm;
369
370 setNr=line[j].trk;
371
372 /* determine if we have a new line, new division or number of points */
373 if(( j!=curj)||( div!=curdiv)||( set[setNr].anz_p!=curn)||(k==0))
374 {
375 curj=j;
376 curn=set[setNr].anz_p;
377 curdiv=div;
378
379 /* realloc the arrays for interpol */
380 if( (l = (double *)realloc( (double *)l, curn*sizeof(double))) == NULL )
381 { printf(" ERROR: realloc failure in splineNodes() l\n\n"); return(-1); }
382 if( (dl = (double *)realloc( (double *)dl, div*sizeof(double))) == NULL )
383 { printf(" ERROR: realloc failure in splineNodes() dl\n\n"); return(-1); }
384 if( (x = (double *)realloc( (double *)x, curn*sizeof(double))) == NULL )
385 { printf(" ERROR: realloc failure in splineNodes() x\n\n"); return(-1); }
386 if( (y = (double *)realloc( (double *)y, curn*sizeof(double))) == NULL )
387 { printf(" ERROR: realloc failure in splineNodes() y\n\n"); return(-1); }
388 if( (z = (double *)realloc( (double *)z, curn*sizeof(double))) == NULL )
389 { printf(" ERROR: realloc failure in splineNodes() z\n\n"); return(-1); }
390
391 /* look if the sequence is ordered in the same way as the line */
392 lp[0]=lp[1]=0;
393 for(i=0; i<set[setNr].anz_p; i++)
394 {
395 if( line[j].p1==set[setNr].pnt[i] ) lp[0]=i;
396 if( line[j].p2==set[setNr].pnt[i] ) lp[1]=i;
397 }
398
399 /* determine the length of the spline, accumulate all dists between points */
400 /* look if the sequence is ordered in the same way as the line */
401 n=1;
402 if( lp[0]<lp[1] )
403 {
404 dl1=lsegm=lmax=l[0]=0.;
405 x[0]=p1[0]=point[set[setNr].pnt[lp[0]]].px;
406 y[0]=p1[1]=point[set[setNr].pnt[lp[0]]].py;
407 z[0]=p1[2]=point[set[setNr].pnt[lp[0]]].pz;
408 for (i=lp[0]+1; i<=lp[1]; i++)
409 {
410 p2[0]=point[set[setNr].pnt[i]].px;
411 p2[1]=point[set[setNr].pnt[i]].py;
412 p2[2]=point[set[setNr].pnt[i]].pz;
413 v_result( p1, p2, p1p2 );
414 x[n]=p1[0]=p2[0];
415 y[n]=p1[1]=p2[1];
416 z[n]=p1[2]=p2[2];
417 lp1p2=v_betrag( p1p2 );
418 lmax+=lp1p2; /* total spline length */
419 l[n]=lmax;
420 if(i==lp[0]) dl1=l[n]; /* spline-length at start of line */
421 if((i>lp[0])&&(i<=lp[1])) lsegm+=lp1p2; /* total line lenght */
422 n++;
423 }
424 }
425 else
426 {
427 dl1=lsegm=lmax=l[0]=0.;
428 x[0]=p1[0]=point[set[setNr].pnt[lp[1]]].px;
429 y[0]=p1[1]=point[set[setNr].pnt[lp[1]]].py;
430 z[0]=p1[2]=point[set[setNr].pnt[lp[1]]].pz;
431 for (i=lp[1]+1; i<=lp[0]; i++)
432 {
433 // printf("point %d %s\n", i, point[set[setNr].pnt[i]].name);
434 p2[0]=point[set[setNr].pnt[i]].px;
435 p2[1]=point[set[setNr].pnt[i]].py;
436 p2[2]=point[set[setNr].pnt[i]].pz;
437 v_result( p1, p2, p1p2 );
438 x[n]=p1[0]=p2[0];
439 y[n]=p1[1]=p2[1];
440 z[n]=p1[2]=p2[2];
441 lp1p2=v_betrag( p1p2 );
442 lmax+=lp1p2;
443 l[n]=lmax;
444 if(i==lp[1]) dl1=l[n]; /* spline-length at start of line */
445 if((i>lp[1])&&(i<=lp[0])) lsegm+=lp1p2; /* total line lenght */
446 n++;
447 }
448 }
449
450 /*
451 printf(" LINE:%s lmax:%lf\n", line[j].name, lmax);
452 for (i=0; i<n; i++)
453 {
454 printf("%d %lf %lf %lf %lf %lf %lf %lf \n",i, dl1,lsegm,lmax,l[i],x[i],y[i],z[i]);
455 }
456 */
457
458 /* berechnung der elementgroessen */
459 dl[0]=le=sum_l=1.;
460 for(i=1; i<div; i++)
461 {
462 le= le*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
463 sum_l+=le; /* Summe aller relativen Elementgroessen */
464 dl[i]= sum_l;
465 /* printf("i:%d l:%lf suml:%lf\n", i, l, sum_l); */
466 }
467
468 /* scalierung der elemente auf die linienlaenge */
469 /* Summe aller Elementgroessen zwischen 1. u i-linienpkt */
470 for(i=0; i<div; i++)
471 {
472 dl[i]= dl1 + dl[i]/sum_l* lsegm;
473 /* printf("i:%d dl:%lf\n", i,dl[i]); */
474 }
475 }
476 else iopt=1;
477
478 /* calculate the node-pos. */
479 mode=1;
480 pn[0] = intpol3( l, x, n, dl[k], &mode, 0., iopt );
481 if(mode==-1)
482 {
483 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
484 mode=1;
485 pn[0] = intpol2( l, x, n, dl[k], &mode );
486 }
487 mode=1;
488 pn[1] = intpol3( l, y, n, dl[k], &mode, 0., iopt );
489 if(mode==-1)
490 {
491 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
492 mode=1;
493 pn[0] = intpol2( l, y, n, dl[k], &mode );
494 }
495 mode=1;
496 pn[2] = intpol3( l, z, n, dl[k], &mode, 0., iopt );
497 if(mode==-1)
498 {
499 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
500 mode=1;
501 pn[0] = intpol2( l, z, n, dl[k], &mode );
502 }
503 /*
504 printf ("dl:%lf node[%d] lmax:%lf div:%d pos:%lf %lf %lf\n", dl[k], k, lmax, div, pn[0],pn[1],pn[2]);
505 */
506 return(1);
507 }
508
509
510 /* prototype, preliminary version */
511
nurlNodes(int j,int k,int div,double * pn)512 int nurlNodes( int j, int k, int div, double *pn )
513 /* gives node-positions on a nurbs-line due to line-div */
514 /* j: line-index, k: nodenr (starts with 0), pn[3]: x,y,z */
515 {
516 static int curk=100, curj=-1;
517 static double p1[3], p2[3], p1p2[3], ep1p2[3], lp1p2;
518 static double l, p1pn[3];
519
520 if(( j!=curj)||( k<=curk))
521 {
522 curj=j;
523 p1[0]=point[line[j].p1].px;
524 p1[1]=point[line[j].p1].py;
525 p1[2]=point[line[j].p1].pz;
526 p2[0]=point[line[j].p2].px;
527 p2[1]=point[line[j].p2].py;
528 p2[2]=point[line[j].p2].pz;
529 v_result( p1, p2, p1p2 );
530 lp1p2=v_betrag( p1p2 );
531 v_norm( p1p2, ep1p2 );
532 }
533 curk=k;
534
535 /* calculate the node-pos. */
536 if (lp1p2==0.)
537 {
538 pn[0]=p1[0]; pn[1]=p1[1]; pn[2]=p1[2];
539 }
540 else
541 {
542 l=lp1p2/div * (k+1.);
543 v_scal(&l, ep1p2, p1pn );
544 v_add( p1, p1pn, pn );
545 }
546 return(1);
547 }
548
549
550 int glob_line=0;
thread_genNodeFromLine(void * vargp)551 void *thread_genNodeFromLine(void *vargp)
552 {
553 int i,j,k,l,u;
554 int setNr, trkNr;
555 int *nl;
556 int ebuf[20];
557 double pn[3];
558
559 double *dl=NULL;
560 double p1pn[3];
561
562 double *dalfa=NULL;
563 double p1[3], p2[3], pc[3];
564 double p1p2[3], ep1p2[3], lp1p2;
565 double pcp1[3], lpcp1;
566 double pcp2[3], lpcp2;
567 double pcpn[3], Tp1p2[3], pcT[3], epcT[3];
568 double rad, alfa, beta, T;
569 double rad_cur, ll, sum_l;
570
571 int n, lp[2], iopt=0, mode, renderFlag;
572 double lmax, le, *lls=NULL, *x=NULL, *y=NULL, *z=NULL;
573 double dl1, lsegm;
574 int *param;
575 param=(int *)vargp;
576 setNr=param[0];
577 renderFlag=param[2];
578
579 /* gives node-positions on a line due to line-div */
580 while(1)
581 {
582 sem_wait(&sem_g);
583 l=glob_line++;
584 sem_post(&sem_g);
585 if(l>=param[1]) break;
586 j=set[setNr].line[l];
587 line[j].fail=1;
588
589 if( line[j].name == (char *)NULL ) continue;
590 if( line[j].div < 1 )
591 {
592 param[4]++;
593 seta(set_nomesh,"l",j);
594 continue;
595 }
596
597 if ((line[j].nod = (int *)realloc( (int *)line[j].nod, (line[j].div)*sizeof(int)) ) == NULL )
598 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[j].name); return((void *)-1); }
599
600 if(printFlag)
601 printf ("l:%d tid:%d meshing line:%s typ:%c\n",l, param[3], line[j].name, line[j].typ);
602
603 p1[0]=point[line[j].p1].px;
604 p1[1]=point[line[j].p1].py;
605 p1[2]=point[line[j].p1].pz;
606 p2[0]=point[line[j].p2].px;
607 p2[1]=point[line[j].p2].py;
608 p2[2]=point[line[j].p2].pz;
609 if (line[j].typ=='a')
610 {
611 // was: if(arcNodes( j, k,line[j].div, pn )==-1) { param[4]++; pre_seta(specialset->nomesh, "l", line[j].name); }
612 if( (dalfa = (double *)realloc( (double *)dalfa, line[j].div*sizeof(double))) == NULL )
613 { printf(" ERROR: realloc failure in arcNodes()\n\n"); return((void *)-1); }
614
615 pc[0]=point[line[j].trk].px;
616 pc[1]=point[line[j].trk].py;
617 pc[2]=point[line[j].trk].pz;
618
619 v_result( p1, p2, p1p2 );
620 v_result( pc, p1, pcp1 );
621 v_result( pc, p2, pcp2 );
622
623 lp1p2=v_betrag( p1p2 );
624 lpcp1=v_betrag( pcp1 );
625 lpcp2=v_betrag( pcp2 );
626
627 rad=(lpcp1+lpcp2)/2.;
628 alfa=asin( (lp1p2/2.)/rad ) *2.;
629 beta=(PI-alfa)/2.;
630
631 /* berechnung der elementgroessen */
632 dalfa[0]=ll=sum_l=1.;
633 for(i=1; i<line[j].div; i++)
634 {
635 ll= ll*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
636 sum_l+=ll; /* Summe aller relativen Elementgroessen */
637 dalfa[i]= sum_l;
638 // printf("i:%d ll:%lf suml:%lf\n", i, ll, sum_l);
639 }
640 for(i=0; i<line[j].div; i++)
641 {
642 dalfa[i]= dalfa[i]/sum_l * alfa; /* Summe aller Elementgroessen */
643 // printf("i:%d dalfa:%lf\n", i,dalfa[i]);
644 }
645 for (k=0; k<line[j].div-1; k++)
646 {
647 if ((lp1p2==0.)||(lpcp1==0.)||(lpcp2==0.))
648 {
649 pn[0]=point[line[j].p1].px;
650 pn[1]=point[line[j].p1].py;
651 pn[2]=point[line[j].p1].pz;
652 }
653 else
654 {
655 T=rad/( cos(dalfa[k])/sin(dalfa[k])*sin(beta) + cos(beta) );
656 v_norm( p1p2, ep1p2 );
657 v_scal(&T, ep1p2, Tp1p2 );
658 v_add( pcp1, Tp1p2, pcT );
659 v_norm( pcT, epcT );
660 rad_cur=(lpcp1*(double)(line[j].div-(k+1))/(double)line[j].div) + (lpcp2*((double)(k+1)/(double)line[j].div));
661 v_scal(&rad_cur, epcT, pcpn );
662 v_add( pc, pcpn, pn );
663 }
664 sem_wait(&sem_n);
665 nod( apre, &npre, 0, apre->nmax+1, pn[0], pn[1], pn[2], 0 );
666 line[j].nod[k]=apre->nmax;
667 sem_post(&sem_n);
668 //sprintf( buffer,"%d ", line[j].nod[k] );
669 }
670 free(dalfa);
671 dalfa=NULL;
672 }
673 else if (line[j].typ=='s')
674 {
675 //was: if(splineNodes( j, k,line[j].div, pn )==-1) { param[4]++; pre_seta(specialset->nomesh, "l", line[j].name); }
676 trkNr=line[j].trk;
677
678 /* realloc the arrays for interpol */
679 if( (lls = (double *)realloc( (double *)lls, (1+set[trkNr].anz_p)*sizeof(double))) == NULL )
680 { printf(" ERROR: realloc failure in splineNodes() l\n\n"); return((void *)-1); }
681 if( (dl = (double *)realloc( (double *)dl, line[j].div*sizeof(double))) == NULL )
682 { printf(" ERROR: realloc failure in splineNodes() dl\n\n"); return((void *)-1); }
683 if( (x = (double *)realloc( (double *)x, set[trkNr].anz_p*sizeof(double))) == NULL )
684 { printf(" ERROR: realloc failure in splineNodes() x\n\n"); return((void *)-1); }
685 if( (y = (double *)realloc( (double *)y, set[trkNr].anz_p*sizeof(double))) == NULL )
686 { printf(" ERROR: realloc failure in splineNodes() y\n\n"); return((void *)-1); }
687 if( (z = (double *)realloc( (double *)z, set[trkNr].anz_p*sizeof(double))) == NULL )
688 { printf(" ERROR: realloc failure in splineNodes() z\n\n"); return((void *)-1); }
689
690 /* look if the sequence is ordered in the same way as the line */
691 lp[0]=lp[1]=0;
692 for(i=0; i<set[trkNr].anz_p; i++)
693 {
694 if( line[j].p1==set[trkNr].pnt[i] ) lp[0]=i;
695 if( line[j].p2==set[trkNr].pnt[i] ) lp[1]=i;
696 }
697
698 /* determine the length of the spline, accumulate all dists between points */
699 /* look if the sequence is ordered in the same way as the line */
700 n=1;
701 if( lp[0]<lp[1] )
702 {
703 dl1=lsegm=lmax=lls[0]=0.;
704 x[0]=p1[0]=point[set[trkNr].pnt[lp[0]]].px;
705 y[0]=p1[1]=point[set[trkNr].pnt[lp[0]]].py;
706 z[0]=p1[2]=point[set[trkNr].pnt[lp[0]]].pz;
707 for (i=lp[0]+1; i<=lp[1]; i++)
708 {
709 p2[0]=point[set[trkNr].pnt[i]].px;
710 p2[1]=point[set[trkNr].pnt[i]].py;
711 p2[2]=point[set[trkNr].pnt[i]].pz;
712 v_result( p1, p2, p1p2 );
713 x[n]=p1[0]=p2[0];
714 y[n]=p1[1]=p2[1];
715 z[n]=p1[2]=p2[2];
716 lp1p2=v_betrag( p1p2 );
717 lmax+=lp1p2; /* total spline length */
718 lls[n]=lmax;
719 if(i==lp[0]) dl1=lls[n]; /* spline-length at start of line */
720 if((i>lp[0])&&(i<=lp[1])) lsegm+=lp1p2; /* total line lenght */
721 n++;
722 }
723 }
724 else
725 {
726 dl1=lsegm=lmax=lls[0]=0.;
727 x[0]=p1[0]=point[set[trkNr].pnt[lp[1]]].px;
728 y[0]=p1[1]=point[set[trkNr].pnt[lp[1]]].py;
729 z[0]=p1[2]=point[set[trkNr].pnt[lp[1]]].pz;
730 for (i=lp[1]+1; i<=lp[0]; i++)
731 {
732 // printf("point %d %s\n", i, point[set[trkNr].pnt[i]].name);
733 p2[0]=point[set[trkNr].pnt[i]].px;
734 p2[1]=point[set[trkNr].pnt[i]].py;
735 p2[2]=point[set[trkNr].pnt[i]].pz;
736 v_result( p1, p2, p1p2 );
737 x[n]=p1[0]=p2[0];
738 y[n]=p1[1]=p2[1];
739 z[n]=p1[2]=p2[2];
740 lp1p2=v_betrag( p1p2 );
741 lmax+=lp1p2;
742 lls[n]=lmax;
743 if(i==lp[1]) dl1=lls[n]; /* spline-length at start of line */
744 if((i>lp[1])&&(i<=lp[0])) lsegm+=lp1p2; /* total line lenght */
745 n++;
746 }
747 }
748
749 /*
750 printf(" LINE:%s lmax:%lf\n", line[j].name, lmax);
751 for (i=0; i<n; i++)
752 {
753 printf("%d %lf %lf %lf %lf %lf %lf %lf \n",i, dl1,lsegm,lmax,lls[i],x[i],y[i],z[i]);
754 }
755 */
756
757 /* berechnung der elementgroessen */
758 dl[0]=le=sum_l=1.;
759 for(i=1; i<line[j].div; i++)
760 {
761 le= le*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
762 sum_l+=le; /* Summe aller relativen Elementgroessen */
763 dl[i]= sum_l;
764 /* printf("i:%d l:%lf suml:%lf\n", i, l, sum_l); */
765 }
766
767 /* scalierung der elemente auf die linienlaenge */
768 /* Summe aller Elementgroessen zwischen 1. u i-linienpkt */
769 for(i=0; i<line[j].div; i++)
770 {
771 dl[i]= dl1 + dl[i]/sum_l* lsegm;
772 /* printf("i:%d dl:%lf\n", i,dl[i]); */
773 }
774
775 for (k=0; k<line[j].div-1; k++)
776 {
777 mode=1;
778 pn[0] = intpol3( lls, x, n, dl[k], &mode, 0., iopt );
779 if(mode==-1)
780 {
781 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
782 mode=1;
783 pn[0] = intpol2( lls, x, n, dl[k], &mode );
784 }
785 mode=1;
786 pn[1] = intpol3( lls, y, n, dl[k], &mode, 0., iopt );
787 if(mode==-1)
788 {
789 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
790 mode=1;
791 pn[0] = intpol2( lls, y, n, dl[k], &mode );
792 }
793 mode=1;
794 pn[2] = intpol3( lls, z, n, dl[k], &mode, 0., iopt );
795 if(mode==-1)
796 {
797 if(printFlag) printf("WARNING: intpol3 could not create the spline coefficients, intpol2 used\n");
798 mode=1;
799 pn[0] = intpol2( lls, z, n, dl[k], &mode );
800 }
801 if(!iopt) iopt=1;
802
803 sem_wait(&sem_n);
804 nod( apre, &npre, 0, apre->nmax+1, pn[0], pn[1], pn[2], 0 );
805 line[j].nod[k]=apre->nmax;
806 sem_post(&sem_n);
807 //sprintf( buffer,"%d ", line[j].nod[k] );
808 }
809 free(dl);
810 free(lls);
811 free(x);
812 free(y);
813 free(z);
814 dl=lls=x=y=z=NULL;
815 }
816 else
817 {
818 //was: if(straightNodes( j, k,line[j].div, pn, dl)==-1) { param[4]++; pre_seta(specialset->nomesh, "l", line[j].name); }
819 if( (dl = (double *)realloc( (double *)dl, line[j].div*sizeof(double))) == NULL )
820 { printf(" ERROR: realloc failure in straightNodes()\n\n"); return((void *)-1); }
821
822 v_result( p1, p2, p1p2 );
823 lp1p2=v_betrag( p1p2 );
824 v_norm( p1p2, ep1p2 );
825
826 /* berechnung der elementgroessen */
827 dl[0]=ll=sum_l=1.;
828 for(i=1; i<line[j].div; i++)
829 {
830 ll= ll*line[j].bias; /* aktuelle relative Elementgroesse (1. Element ist 1 lang) */
831 sum_l+=ll; /* Summe aller relativen Elementgroessen */
832 dl[i]= sum_l;
833 /* printf("i:%d ll:%lf suml:%lf\n", i, ll, sum_l); */
834 }
835 for(i=0; i<line[j].div; i++)
836 {
837 dl[i]= dl[i]/sum_l* lp1p2; /* Summe aller Elementgroessen */
838 /* printf("i:%d dl:%lf\n", i,dl[i]); */
839 }
840 for (k=0; k<line[j].div-1; k++)
841 {
842 if (lp1p2==0.)
843 {
844 pn[0]=p1[0]; pn[1]=p1[1]; pn[2]=p1[2];
845 }
846 else
847 {
848 v_scal(&dl[k], ep1p2, p1pn );
849 v_add( p1, p1pn, pn );
850 /* printf("pn:%f %f %f\n",pn[0],pn[1],pn[2]); */
851 }
852 sem_wait(&sem_n);
853 nod( apre, &npre, 0, apre->nmax+1, pn[0], pn[1], pn[2], 0 );
854 line[j].nod[k]=apre->nmax;
855 sem_post(&sem_n);
856 //sprintf( buffer,"%d ", line[j].nod[k] );
857 }
858 free(dl);
859 dl=NULL;
860 }
861 line[j].nn=k;
862 line[j].fail=0;
863
864 /* correct midside-node-positions if a bias is defined */
865 if(line[j].bias!=1.)
866 {
867 if(line[j].etyp==12) goto corrMidsideNodes;
868 for (u=0; u<set[setNr].anz_s; u++)
869 if((surf[set[setNr].surf[u]].etyp==8)||(surf[set[setNr].surf[u]].etyp==10)) goto corrMidsideNodes;
870 for (u=0; u<set[setNr].anz_b; u++)
871 if(body[set[setNr].body[u]].etyp==4) goto corrMidsideNodes;
872 goto no_corrMidsideNodes;
873
874 corrMidsideNodes:;
875 sem_wait(&sem_n);
876 for (k=-1; k<line[j].nn-1; k+=2)
877 {
878 if(k==-1)
879 if(line[j].nn>1) adjustMidsideNode(&npre[point[line[j].p1].nod[0]].nx,&npre[line[j].nod[k+2]].nx,&npre[line[j].nod[k+1]].nx,0);
880 else adjustMidsideNode(&npre[point[line[j].p1].nod[0]].nx,&npre[point[line[j].p2].nod[0]].nx,&npre[line[j].nod[k+1]].nx,0);
881 else if(k==line[j].nn-2)
882 adjustMidsideNode(&npre[line[j].nod[k]].nx,&npre[point[line[j].p2].nod[0]].nx,&npre[line[j].nod[k+1]].nx,0);
883 else
884 adjustMidsideNode(&npre[line[j].nod[k]].nx,&npre[line[j].nod[k+2]].nx,&npre[line[j].nod[k+1]].nx,0);
885 }
886 sem_post(&sem_n);
887
888 no_corrMidsideNodes:;
889 }
890
891 /* generation of elements */
892 k=0;
893
894 if ((line[j].div>0)&&(!renderFlag))
895 {
896 if (line[j].etyp==11)
897 {
898 if ((nl = (int *)malloc( (line[j].div+2)*sizeof(int)) ) == NULL )
899 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[j].name);
900 return((void *)0); }
901 /* elemente duerfen nur allociert werden wenn noetig (NULL-Pointer wird irgendwo abgefragt ) */
902 if ((line[j].elem = (int *)realloc( (int *)line[j].elem, (line[j].div)*sizeof(int)) ) == NULL )
903 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[j].name);
904 return((void *)0); }
905
906 nl[0]=point[line[j].p1].nod[0];
907 for (u=1; u<line[j].div; u++)
908 {
909 nl[u]=line[j].nod[u-1];
910 }
911 nl[u]=point[line[j].p2].nod[0];
912
913 for (u=0; u<line[j].div; u++)
914 {
915 sem_wait(&sem_n);
916 elem_define(anz,&e_enqire, anz->enext++, 11, &nl[u], 0, line[j].eattr );
917 line[j].elem[k]=anz->emax;
918 sem_post(&sem_n);
919 k++;
920 }
921 free(nl);
922 }
923
924 if (line[j].etyp==12)
925 {
926 if ((nl = (int *)malloc( (line[j].div+2)*sizeof(int)) ) == NULL )
927 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[j].name);
928 return((void *)0); }
929 /* elemente duerfen nur allociert werden wenn noetig (NULL-Pointer wird irgendwo abgefragt ) */
930 if ((line[j].elem = (int *)realloc( (int *)line[j].elem, (line[j].div/2)*sizeof(int)) ) == NULL )
931 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[j].name);
932 return((void *)0); }
933
934 nl[0]=point[line[j].p1].nod[0];
935 for (u=1; u<line[j].div; u++)
936 {
937 nl[u]=line[j].nod[u-1];
938 }
939 nl[u]=point[line[j].p2].nod[0];
940
941 for (u=0; u<line[j].div-1; u+=2)
942 {
943 ebuf[0]=nl[u];
944 ebuf[1]=nl[u+2];
945 ebuf[2]=nl[u+1];
946 sem_wait(&sem_n);
947 elem_define(anz,&e_enqire, anz->enext++, 12, ebuf, 0, line[j].eattr );
948 line[j].elem[k]=anz->emax;
949 sem_post(&sem_n);
950 k++;
951 }
952 free(nl);
953 }
954 }
955 line[j].ne=k;
956 }
957 return((void *)1);
958 }
959
960
961
meshLines(int setNr,int renderFlag)962 int meshLines( int setNr, int renderFlag)
963 {
964 int i;
965 int anz_l, meshflag, noLineMesh=0;
966
967 typedef struct {
968 int vargp[6];
969 } Threadargs;
970 Threadargs *targ=NULL;
971 pthread_t *tid=NULL;
972 int nlocalThreads;
973
974 /* are elements requested? */
975 anz_l=set[setNr].anz_l;
976 if(renderFlag) meshflag=1;
977 else
978 {
979 meshflag=0;
980 for (i=0; i<anz_l; i++)
981 {
982 if(( line[set[setNr].line[i]].etyp==11)||( line[set[setNr].line[i]].etyp==12)) { meshflag=1; break; }
983 }
984 for (i=0; i<set[setNr].anz_s; i++)
985 {
986 if(( surf[set[setNr].surf[i]].etyp==7)||
987 ( surf[set[setNr].surf[i]].etyp==8)||
988 ( surf[set[setNr].surf[i]].etyp==9)||
989 ( surf[set[setNr].surf[i]].etyp==10)) { meshflag=1; break; }
990 }
991 for (i=0; i<set[setNr].anz_b; i++)
992 {
993 if(( body[set[setNr].body[i]].etyp==1)||( body[set[setNr].body[i]].etyp==4)) { meshflag=1; break; }
994 }
995 }
996 if (!meshflag) return(-1);
997
998 /* threaded node generation */
999 if(anz->threads>anz_l) { nlocalThreads=anz_l; }
1000 else nlocalThreads=anz->threads;
1001 if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
1002 if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
1003 for(i=0; i<nlocalThreads; i++)
1004 {
1005 targ[i].vargp[0]=setNr;
1006 targ[i].vargp[1]=anz_l;
1007 targ[i].vargp[2]=renderFlag;
1008 targ[i].vargp[3]=i;
1009 targ[i].vargp[4]=0; // counts noLineMesh
1010 //printf("thread:%d lines\n",i);
1011 // the following line might replace the pthread_xx functions to check them
1012 //noLineMesh+=(int)thread_genNodeFromLine((void *)targ[i].vargp);
1013 pthread_create(&tid[i],NULL,thread_genNodeFromLine,(void *)targ[i].vargp);
1014 }
1015 for(i=0; i<nlocalThreads; i++)
1016 {
1017 pthread_join(tid[i], NULL);
1018 noLineMesh+=targ[i].vargp[4];
1019 }
1020 glob_line=0;
1021
1022 free(tid); tid=NULL;
1023 free(targ); targ=NULL;
1024
1025 return(noLineMesh);
1026 }
1027
1028
1029 /****************************************************************/
1030 /* get node-numbers of surface-edge-nodes */
1031 /* unused areas <n_uv(u,v)> return "-1" */
1032 /* */
1033 /* */
1034 /* v */
1035 /*vmax^ */
1036 /* | */
1037 /* | */
1038 /* | */
1039 /*div_| */
1040 /*l[1]| */
1041 /* | */
1042 /* |________________________> u */
1043 /* n_uv(0,0) div_l[0] umax */
1044 /****************************************************************/
edgeNodes(int vmax,int umax,int j,int * n_uv)1045 void edgeNodes( int vmax, int umax, int j, int *n_uv )
1046 {
1047 int k,l,n,m,o,p, u,v, nodnr;
1048
1049 for( n=0; n<(umax*vmax); n++) n_uv[n]=-1;
1050
1051 /* store nodes of edge0 */
1052 n=0; /* edge Nr */
1053 u=0; /* surf parameter */
1054 v=0; /* surf parameter */
1055
1056 k=surf[j].l[n];
1057 if( surf[j].typ[n]=='c' )
1058 {
1059 if(surf[j].o[n]=='+')
1060 {
1061 for( l=0; l<lcmb[k].nl; l++ )
1062 {
1063 m=lcmb[k].l[l];
1064 if(lcmb[k].o[l]=='+')
1065 {
1066 if (l==0)
1067 {
1068 p=line[m].p1; /* Anfangsknoten */
1069 nodnr=point[p].nod[0];
1070 n_uv[u*vmax +v]=nodnr;
1071 u++;
1072 }
1073 for( o=0; o<line[m].div-1; o++) /* alle Zwischenknoten */
1074 {
1075 nodnr=line[m].nod[o];
1076 n_uv[u*vmax +v]=nodnr;
1077 u++;
1078 }
1079 p=line[m].p2; /* Endknoten */
1080 nodnr=point[p].nod[0];
1081 n_uv[u*vmax +v]=nodnr;
1082 u++;
1083 }
1084 else
1085 {
1086 if (l==0)
1087 {
1088 p=line[m].p2;
1089 nodnr=point[p].nod[0];
1090 n_uv[u*vmax +v]=nodnr;
1091 u++;
1092 }
1093 for( o=line[m].div-2; o>-1; o--)
1094 {
1095 nodnr=line[m].nod[o];
1096 n_uv[u*vmax +v]=nodnr;
1097 u++;
1098 }
1099 p=line[m].p1;
1100 nodnr=point[p].nod[0];
1101 n_uv[u*vmax +v]=nodnr;
1102 u++;
1103 }
1104 }
1105 }
1106 else /* edge is - oriented */
1107 {
1108 for( l=lcmb[k].nl-1; l>-1; l-- )
1109 {
1110 m=lcmb[k].l[l];
1111 if(lcmb[k].o[l]=='-')
1112 {
1113 if (l==lcmb[k].nl-1)
1114 {
1115 p=line[m].p1;
1116 nodnr=point[p].nod[0];
1117 n_uv[u*vmax +v]=nodnr;
1118 u++;
1119 }
1120 for( o=0; o<line[m].div-1; o++)
1121 {
1122 nodnr=line[m].nod[o];
1123 n_uv[u*vmax +v]=nodnr;
1124 u++;
1125 }
1126 p=line[m].p2;
1127 nodnr=point[p].nod[0];
1128 n_uv[u*vmax +v]=nodnr;
1129 u++;
1130 }
1131 else
1132 {
1133 if (l==lcmb[k].nl-1)
1134 {
1135 p=line[m].p2;
1136 nodnr=point[p].nod[0];
1137 n_uv[u*vmax +v]=nodnr;
1138 u++;
1139 }
1140 for( o=line[m].div-2; o>-1; o--)
1141 {
1142 nodnr=line[m].nod[o];
1143 n_uv[u*vmax +v]=nodnr;
1144 u++;
1145 }
1146 p=line[m].p1;
1147 nodnr=point[p].nod[0];
1148 n_uv[u*vmax +v]=nodnr;
1149 u++;
1150 }
1151 }
1152 }
1153 }
1154 else /* its a line */
1155 {
1156 m=surf[j].l[n];
1157 if(surf[j].o[n]=='+')
1158 {
1159 p=line[m].p1;
1160 nodnr=point[p].nod[0];
1161 n_uv[u*vmax +v]=nodnr;
1162 u++;
1163 for( o=0; o<line[m].div-1; o++)
1164 {
1165 nodnr=line[m].nod[o];
1166 n_uv[u*vmax +v]=nodnr;
1167 u++;
1168 }
1169 p=line[m].p2;
1170 nodnr=point[p].nod[0];
1171 n_uv[u*vmax +v]=nodnr;
1172 u++;
1173 }
1174 else
1175 {
1176 p=line[m].p2;
1177 nodnr=point[p].nod[0];
1178 n_uv[u*vmax +v]=nodnr;
1179 u++;
1180 for( o=line[m].div-2; o>-1; o--)
1181 {
1182 nodnr=line[m].nod[o];
1183 n_uv[u*vmax +v]=nodnr;
1184 u++;
1185 }
1186 p=line[m].p1;
1187 nodnr=point[p].nod[0];
1188 n_uv[u*vmax +v]=nodnr;
1189 u++;
1190 }
1191 }
1192
1193
1194 /* store nodes of edge1 */
1195 n=1; /* edge Nr */
1196 u=umax-1; /* surf parameter */
1197 v=0; /* surf parameter */
1198
1199 k=surf[j].l[n];
1200 if( surf[j].typ[n]=='c' )
1201 {
1202 if(surf[j].o[n]=='+')
1203 {
1204 for( l=0; l<lcmb[k].nl; l++ )
1205 {
1206 m=lcmb[k].l[l];
1207 if(lcmb[k].o[l]=='+')
1208 {
1209 if (l==0)
1210 {
1211 p=line[m].p1; /* Anfangsknoten */
1212 nodnr=point[p].nod[0];
1213 n_uv[u*vmax +v]=nodnr;
1214 v++;
1215 }
1216 for( o=0; o<line[m].div-1; o++) /* alle Zwischenknoten */
1217 {
1218 nodnr=line[m].nod[o];
1219 n_uv[u*vmax +v]=nodnr;
1220 v++;
1221 }
1222 p=line[m].p2; /* Endknoten */
1223 nodnr=point[p].nod[0];
1224 n_uv[u*vmax +v]=nodnr;
1225 v++;
1226 }
1227 else
1228 {
1229 if (l==0)
1230 {
1231 p=line[m].p2;
1232 nodnr=point[p].nod[0];
1233 n_uv[u*vmax +v]=nodnr;
1234 v++;
1235 }
1236 for( o=line[m].div-2; o>-1; o--)
1237 {
1238 nodnr=line[m].nod[o];
1239 n_uv[u*vmax +v]=nodnr;
1240 v++;
1241 }
1242 p=line[m].p1;
1243 nodnr=point[p].nod[0];
1244 n_uv[u*vmax +v]=nodnr;
1245 v++;
1246 }
1247 }
1248 }
1249 else /* edge is - oriented */
1250 {
1251 for( l=lcmb[k].nl-1; l>-1; l-- )
1252 {
1253 m=lcmb[k].l[l];
1254 if(lcmb[k].o[l]=='-')
1255 {
1256 if (l==lcmb[k].nl-1)
1257 {
1258 p=line[m].p1;
1259 nodnr=point[p].nod[0];
1260 n_uv[u*vmax +v]=nodnr;
1261 v++;
1262 }
1263 for( o=0; o<line[m].div-1; o++)
1264 {
1265 nodnr=line[m].nod[o];
1266 n_uv[u*vmax +v]=nodnr;
1267 v++;
1268 }
1269 p=line[m].p2;
1270 nodnr=point[p].nod[0];
1271 n_uv[u*vmax +v]=nodnr;
1272 v++;
1273 }
1274 else
1275 {
1276 if (l==lcmb[k].nl-1)
1277 {
1278 p=line[m].p2;
1279 nodnr=point[p].nod[0];
1280 n_uv[u*vmax +v]=nodnr;
1281 v++;
1282 }
1283 for( o=line[m].div-2; o>-1; o--)
1284 {
1285 nodnr=line[m].nod[o];
1286 n_uv[u*vmax +v]=nodnr;
1287 v++;
1288 }
1289 p=line[m].p1;
1290 nodnr=point[p].nod[0];
1291 n_uv[u*vmax +v]=nodnr;
1292 v++;
1293 }
1294 }
1295 }
1296 }
1297 else /* its a line */
1298 {
1299 m=surf[j].l[n];
1300 if(surf[j].o[n]=='+')
1301 {
1302 p=line[m].p1;
1303 nodnr=point[p].nod[0];
1304 n_uv[u*vmax +v]=nodnr;
1305 v++;
1306 for( o=0; o<line[m].div-1; o++)
1307 {
1308 nodnr=line[m].nod[o];
1309 n_uv[u*vmax +v]=nodnr;
1310 v++;
1311 }
1312 p=line[m].p2;
1313 nodnr=point[p].nod[0];
1314 n_uv[u*vmax +v]=nodnr;
1315 v++;
1316 }
1317 else
1318 {
1319 p=line[m].p2;
1320 nodnr=point[p].nod[0];
1321 n_uv[u*vmax +v]=nodnr;
1322 v++;
1323 for( o=line[m].div-2; o>-1; o--)
1324 {
1325 nodnr=line[m].nod[o];
1326 n_uv[u*vmax +v]=nodnr;
1327 v++;
1328 }
1329 p=line[m].p1;
1330 nodnr=point[p].nod[0];
1331 n_uv[u*vmax +v]=nodnr;
1332 v++;
1333 }
1334 }
1335
1336
1337 /* store nodes of edge2 */
1338 n=2; /* edge Nr */
1339 u=umax-1; /* surf parameter */
1340 v=vmax-1; /* surf parameter */
1341
1342 k=surf[j].l[n];
1343 if( surf[j].typ[n]=='c' )
1344 {
1345 if(surf[j].o[n]=='+')
1346 {
1347 for( l=0; l<lcmb[k].nl; l++ )
1348 {
1349 m=lcmb[k].l[l];
1350 if(lcmb[k].o[l]=='+')
1351 {
1352 if (l==0)
1353 {
1354 p=line[m].p1; /* Anfangsknoten */
1355 nodnr=point[p].nod[0];
1356 n_uv[u*vmax +v]=nodnr;
1357 u--;
1358 }
1359 for( o=0; o<line[m].div-1; o++) /* alle Zwischenknoten */
1360 {
1361 nodnr=line[m].nod[o];
1362 n_uv[u*vmax +v]=nodnr;
1363 u--;
1364 }
1365 p=line[m].p2; /* Endknoten */
1366 nodnr=point[p].nod[0];
1367 n_uv[u*vmax +v]=nodnr;
1368 u--;
1369 }
1370 else
1371 {
1372 if (l==0)
1373 {
1374 p=line[m].p2;
1375 nodnr=point[p].nod[0];
1376 n_uv[u*vmax +v]=nodnr;
1377 u--;
1378 }
1379 for( o=line[m].div-2; o>-1; o--)
1380 {
1381 nodnr=line[m].nod[o];
1382 n_uv[u*vmax +v]=nodnr;
1383 u--;
1384 }
1385 p=line[m].p1;
1386 nodnr=point[p].nod[0];
1387 n_uv[u*vmax +v]=nodnr;
1388 u--;
1389 }
1390 }
1391 }
1392 else /* edge is - oriented */
1393 {
1394 for( l=lcmb[k].nl-1; l>-1; l-- )
1395 {
1396 m=lcmb[k].l[l];
1397 if(lcmb[k].o[l]=='-')
1398 {
1399 if (l==lcmb[k].nl-1)
1400 {
1401 p=line[m].p1;
1402 nodnr=point[p].nod[0];
1403 n_uv[u*vmax +v]=nodnr;
1404 u--;
1405 }
1406 for( o=0; o<line[m].div-1; o++)
1407 {
1408 nodnr=line[m].nod[o];
1409 n_uv[u*vmax +v]=nodnr;
1410 u--;
1411 }
1412 p=line[m].p2;
1413 nodnr=point[p].nod[0];
1414 n_uv[u*vmax +v]=nodnr;
1415 u--;
1416 }
1417 else
1418 {
1419 if (l==lcmb[k].nl-1)
1420 {
1421 p=line[m].p2;
1422 nodnr=point[p].nod[0];
1423 n_uv[u*vmax +v]=nodnr;
1424 u--;
1425 }
1426 for( o=line[m].div-2; o>-1; o--)
1427 {
1428 nodnr=line[m].nod[o];
1429 n_uv[u*vmax +v]=nodnr;
1430 u--;
1431 }
1432 p=line[m].p1;
1433 nodnr=point[p].nod[0];
1434 n_uv[u*vmax +v]=nodnr;
1435 u--;
1436 }
1437 }
1438 }
1439 }
1440 else /* its a line */
1441 {
1442 m=surf[j].l[n];
1443 if(surf[j].o[n]=='+')
1444 {
1445 p=line[m].p1;
1446 nodnr=point[p].nod[0];
1447 n_uv[u*vmax +v]=nodnr;
1448 u--;
1449 for( o=0; o<line[m].div-1; o++)
1450 {
1451 nodnr=line[m].nod[o];
1452 n_uv[u*vmax +v]=nodnr;
1453 u--;
1454 }
1455 p=line[m].p2;
1456 nodnr=point[p].nod[0];
1457 n_uv[u*vmax +v]=nodnr;
1458 u--;
1459 }
1460 else
1461 {
1462 p=line[m].p2;
1463 nodnr=point[p].nod[0];
1464 n_uv[u*vmax +v]=nodnr;
1465 u--;
1466 for( o=line[m].div-2; o>-1; o--)
1467 {
1468 nodnr=line[m].nod[o];
1469 n_uv[u*vmax +v]=nodnr;
1470 u--;
1471 }
1472 p=line[m].p1;
1473 nodnr=point[p].nod[0];
1474 n_uv[u*vmax +v]=nodnr;
1475 u--;
1476 }
1477 }
1478
1479
1480 /* store nodes of edge3 */
1481 n=3; /* edge Nr */
1482 u=0; /* surf parameter */
1483 v=vmax-1; /* surf parameter */
1484
1485 k=surf[j].l[n];
1486 if( surf[j].typ[n]=='c' )
1487 {
1488 if(surf[j].o[n]=='+')
1489 {
1490 for( l=0; l<lcmb[k].nl; l++ )
1491 {
1492 m=lcmb[k].l[l];
1493 if(lcmb[k].o[l]=='+')
1494 {
1495 if (l==0)
1496 {
1497 p=line[m].p1; /* Anfangsknoten */
1498 nodnr=point[p].nod[0];
1499 n_uv[u*vmax +v]=nodnr;
1500 v--;
1501 }
1502 for( o=0; o<line[m].div-1; o++) /* alle Zwischenknoten */
1503 {
1504 nodnr=line[m].nod[o];
1505 n_uv[u*vmax +v]=nodnr;
1506 v--;
1507 }
1508 p=line[m].p2; /* Endknoten */
1509 nodnr=point[p].nod[0];
1510 n_uv[u*vmax +v]=nodnr;
1511 v--;
1512 }
1513 else
1514 {
1515 if (l==0)
1516 {
1517 p=line[m].p2;
1518 nodnr=point[p].nod[0];
1519 n_uv[u*vmax +v]=nodnr;
1520 v--;
1521 }
1522 for( o=line[m].div-2; o>-1; o--)
1523 {
1524 nodnr=line[m].nod[o];
1525 n_uv[u*vmax +v]=nodnr;
1526 v--;
1527 }
1528 p=line[m].p1;
1529 nodnr=point[p].nod[0];
1530 n_uv[u*vmax +v]=nodnr;
1531 v--;
1532 }
1533 }
1534 }
1535 else /* edge is - oriented */
1536 {
1537 for( l=lcmb[k].nl-1; l>-1; l-- )
1538 {
1539 m=lcmb[k].l[l];
1540 if(lcmb[k].o[l]=='-')
1541 {
1542 if (l==lcmb[k].nl-1)
1543 {
1544 p=line[m].p1;
1545 nodnr=point[p].nod[0];
1546 n_uv[u*vmax +v]=nodnr;
1547 v--;
1548 }
1549 for( o=0; o<line[m].div-1; o++)
1550 {
1551 nodnr=line[m].nod[o];
1552 n_uv[u*vmax +v]=nodnr;
1553 v--;
1554 }
1555 p=line[m].p2;
1556 nodnr=point[p].nod[0];
1557 n_uv[u*vmax +v]=nodnr;
1558 v--;
1559 }
1560 else
1561 {
1562 if (l==lcmb[k].nl-1)
1563 {
1564 p=line[m].p2;
1565 nodnr=point[p].nod[0];
1566 n_uv[u*vmax +v]=nodnr;
1567 v--;
1568 }
1569 for( o=line[m].div-2; o>-1; o--)
1570 {
1571 nodnr=line[m].nod[o];
1572 n_uv[u*vmax +v]=nodnr;
1573 v--;
1574 }
1575 p=line[m].p1;
1576 nodnr=point[p].nod[0];
1577 n_uv[u*vmax +v]=nodnr;
1578 v--;
1579 }
1580 }
1581 }
1582 }
1583 else /* its a line */
1584 {
1585 m=surf[j].l[n];
1586 if(surf[j].o[n]=='+')
1587 {
1588 p=line[m].p1;
1589 nodnr=point[p].nod[0];
1590 n_uv[u*vmax +v]=nodnr;
1591 v--;
1592 for( o=0; o<line[m].div-1; o++)
1593 {
1594 nodnr=line[m].nod[o];
1595 n_uv[u*vmax +v]=nodnr;
1596 v--;
1597 }
1598 p=line[m].p2;
1599 nodnr=point[p].nod[0];
1600 n_uv[u*vmax +v]=nodnr;
1601 v--;
1602 }
1603 else
1604 {
1605 p=line[m].p2;
1606 nodnr=point[p].nod[0];
1607 n_uv[u*vmax +v]=nodnr;
1608 v--;
1609 for( o=line[m].div-2; o>-1; o--)
1610 {
1611 nodnr=line[m].nod[o];
1612 n_uv[u*vmax +v]=nodnr;
1613 v--;
1614 }
1615 p=line[m].p1;
1616 nodnr=point[p].nod[0];
1617 n_uv[u*vmax +v]=nodnr;
1618 v--;
1619 }
1620 }
1621 }
1622
1623
1624
1625 /********************************************************/
1626 /* surf has unbalanced edges, check if it is meshable */
1627 /* and calculate the necessary divisions */
1628 /* */
1629 /* the division on edge sb1 will not be changed, all */
1630 /* other edges might have changed divisions. */
1631 /* */
1632 /* in: */
1633 /* div_l[surfedge]: original divisions */
1634 /* */
1635 /* out: */
1636 /* div_a: preliminary div on both side a */
1637 /* div_b: preliminary div on both side b */
1638 /* sa1, sa2, sb1, sb2: stores the surf-edges of a, b */
1639 /* */
1640 /* how a and b are determined: */
1641 /* da<=db da,db are |div_l[]-div_l[]| of opposite */
1642 /* edges */
1643 /* a */
1644 /* | */
1645 /* | +^ */
1646 /* | |_| */
1647 /* |________ b */
1648 /* */
1649 /* */
1650 /* div_l[sb2]<=div_l[sb1] */
1651 /* */
1652 /* necessary divisions: */
1653 /* div_a=a1+(db-da)/2 */
1654 /* div_b=b1 */
1655 /********************************************************/
newDivisions(int * div_l,int * div_a,int * div_b,int * sa1,int * sa2,int * sb1,int * sb2)1656 int newDivisions( int *div_l, int *div_a,int *div_b, int *sa1,int *sa2,int *sb1,int *sb2 )
1657 {
1658
1659 int i,div_max,da,db, dd02,dd13, div_a1,div_a2,div_b1,div_b2;
1660 double fn,dn,n;
1661
1662
1663 dd02=div_l[0]-div_l[2];
1664 dd13=div_l[1]-div_l[3];
1665 if (dd02<0) dd02*=-1;
1666 if (dd13<0) dd13*=-1;
1667 if (dd02==dd13)
1668 {
1669 div_max=0; for(i=0; i<4; i++) if(div_l[i]>div_max) div_max=div_l[i];
1670 if((div_l[2]==div_max)||(div_l[0]==div_max))
1671 {
1672 da=dd02;
1673 db=dd13;
1674 if(div_l[2]<=div_l[0]){ div_a1= div_l[0]+(db-da)/2; div_a2= div_l[2]+(db-da)/2+da; *sa1=0; *sa2=2;}
1675 else { div_a1= div_l[2]+(db-da)/2; div_a2= div_l[0]+(db-da)/2+da; *sa1=2; *sa2=0;}
1676 if(div_l[3]<=div_l[1]){ div_b1= div_l[1]; div_b2= div_l[3]+db; *sb1=1; *sb2=3;}
1677 else { div_b1= div_l[3]; div_b2= div_l[1]+db; *sb1=3; *sb2=1;}
1678 }
1679 else
1680 {
1681 db=dd02;
1682 da=dd13;
1683 if (div_l[3]<=div_l[1]){div_a1= div_l[1]+(db-da)/2; div_a2= div_l[3]+(db-da)/2+da; *sa1=1; *sa2=3;}
1684 else {div_a1= div_l[3]+(db-da)/2; div_a2= div_l[1]+(db-da)/2+da; *sa1=3; *sa2=1;}
1685 if (div_l[2]<=div_l[0]){div_b1= div_l[0]; div_b2= div_l[2]+db; *sb1=0; *sb2=2;}
1686 else {div_b1= div_l[2]; div_b2= div_l[0]+db; *sb1=2; *sb2=0;}
1687 }
1688 }
1689 else
1690 {
1691 if (dd02<dd13)
1692 {
1693 da=dd02;
1694 db=dd13;
1695 if(div_l[2]<=div_l[0]){ div_a1= div_l[0]+(db-da)/2; div_a2= div_l[2]+(db-da)/2+da; *sa1=0; *sa2=2;}
1696 else { div_a1= div_l[2]+(db-da)/2; div_a2= div_l[0]+(db-da)/2+da; *sa1=2; *sa2=0;}
1697 if(div_l[3]<=div_l[1]){ div_b1= div_l[1]; div_b2= div_l[3]+db; *sb1=1; *sb2=3;}
1698 else { div_b1= div_l[3]; div_b2= div_l[1]+db; *sb1=3; *sb2=1;}
1699 }
1700 else
1701 {
1702 db=dd02;
1703 da=dd13;
1704 if (div_l[3]<=div_l[1]){div_a1= div_l[1]+(db-da)/2; div_a2= div_l[3]+(db-da)/2+da; *sa1=1; *sa2=3;}
1705 else {div_a1= div_l[3]+(db-da)/2; div_a2= div_l[1]+(db-da)/2+da; *sa1=3; *sa2=1;}
1706 if (div_l[2]<=div_l[0]){div_b1= div_l[0]; div_b2= div_l[2]+db; *sb1=0; *sb2=2;}
1707 else {div_b1= div_l[2]; div_b2= div_l[0]+db; *sb1=2; *sb2=0;}
1708 }
1709 }
1710 /* check if (db-da)/2 is positive and integer */
1711 fn=(double)(db-da)/2.;
1712 n=(int)fn;
1713 dn=fn-(double)n;
1714 if (dn<0.) dn*=-1.;
1715 if ((fn<0.)||(dn>1e-32))
1716 {
1717 printf(" ERROR: in newDivisions(), surf with the div: %d %d %d %d can not be meshed\n",
1718 div_l[0], div_l[1], div_l[2], div_l[3] );
1719 printf(" (db-da)/2:%lf dn:%lf\n", fn,dn);
1720 return(-1);
1721 }
1722 else if(printFlag) printf("in newDivisions(): meshable unbalanced edges: %d %d %d %d corrected to a1:%d a2:%d b1:%d b2:%d\n", div_l[0], div_l[1], div_l[2], div_l[3], div_a1, div_a2, div_b1, div_b2 );
1723
1724 *div_a=div_a1;
1725 *div_b=div_b1;
1726
1727 /* determine edge sa1. It is always the line before sb1 to create a propper system */
1728 n=*sa1;
1729 if(*sb1==0) *sa1=3;
1730 else *sa1=*sb1-1;
1731 if (*sa1==*sa2) *sa2=n;
1732
1733 return(1);
1734 }
1735
1736
1737
1738 /**************************************************************************/
1739 /* nun die Randknoten durch interpol auf die geaenderten */
1740 /* divisions umrechnen */
1741 /* Dann werden die x[u][v], y[u][v], z[u][v] felder gefuellt */
1742 /* in: */
1743 /* n: stuetzpunktzahl */
1744 /* lx,ly,lz Raumkoordinaten der Linienstuetzpunkte */
1745 /* u,v startwerte */
1746 /* flag flag=0 u laeuft von 0 -> umax-1, v bleibt konstant */
1747 /* flag=1 v laeuft von 1 -> vmax-1 u bleibt konstant */
1748 /* umax, vmax groesse des zu fuellenden feldes */
1749 /* */
1750 /* */
1751 /* */
1752 /* out: */
1753 /* x[u][v] usw. Raumkoordinaten der Randknoten im surfMesher system */
1754 /* */
1755 /* */
1756 /**************************************************************************/
newEdgePositions(int n,int u,int v,int umax,int vmax,double * lx,double * ly,double * lz,double * x,double * y,double * z,int flag)1757 int newEdgePositions( int n, int u,int v,int umax, int vmax, double *lx,double *ly,double *lz, double *x,double *y,double *z, int flag )
1758 {
1759 int i, nnew;
1760 double *ll,fn=0.,dll;
1761 double *nbez=NULL, *dl=NULL, *dlnew=NULL;
1762
1763
1764 /* zuerst wird ein feld mit der lauflaenge ll berechnet */
1765 if ((ll = (double *)malloc( (n)*sizeof(double)) ) == NULL )
1766 { errMsg(" ERROR: realloc failure in newEdgePositions()\n");
1767 return(-1); }
1768 linelength( lx, ly, lz, n, ll );
1769
1770 if(n<3)
1771 {
1772 if (flag) dll=ll[n-1]/(vmax-1); /* linienlaengen-inkrement */
1773 else dll=ll[n-1]/(umax-1); /* linienlaengen-inkrement */
1774 x[u*vmax +v] = lx[0];
1775 y[u*vmax +v] = ly[0];
1776 z[u*vmax +v] = lz[0];
1777 fn=dll;
1778 if (flag)
1779 {
1780 for (v=1; v<vmax-1; v++)
1781 {
1782 x[u*vmax +v] = intpol( ll, lx, n, fn );
1783 y[u*vmax +v] = intpol( ll, ly, n, fn );
1784 z[u*vmax +v] = intpol( ll, lz, n, fn );
1785 fn+=dll;
1786 }
1787 }
1788 else
1789 {
1790 for (u=1; u<umax-1; u++)
1791 {
1792 x[u*vmax +v] = intpol( ll, lx, n, fn );
1793 y[u*vmax +v] = intpol( ll, ly, n, fn );
1794 z[u*vmax +v] = intpol( ll, lz, n, fn );
1795 fn+=dll;
1796 }
1797 }
1798 x[u*vmax +v] = lx[n-1];
1799 y[u*vmax +v] = ly[n-1];
1800 z[u*vmax +v] = lz[n-1];
1801 free(ll);
1802
1803 return(1);
1804 }
1805 /* berechne neue lauflaengen-inkremente auf basis der neuen stuetzpunktzahl */
1806 if (flag) nnew=vmax;
1807 else nnew=umax;
1808
1809 if ((dl = (double *)malloc( (nnew)*sizeof(double)) ) == NULL )
1810 { errMsg(" ERROR: realloc failure in newEdgePositions()\n");
1811 return(-1); }
1812 if ((dlnew = (double *)malloc( (nnew)*sizeof(double)) ) == NULL )
1813 { errMsg(" ERROR: realloc failure in newEdgePositions()\n");
1814 return(-1); }
1815 if ((nbez = (double *)malloc( (nnew)*sizeof(double)) ) == NULL )
1816 { errMsg(" ERROR: realloc failure in newEdgePositions()\n");
1817 return(-1); }
1818
1819 for (i=1; i<n; i++) nbez[i-1]= (double)i/(double)(n-1);
1820 for (i=1; i<n; i++)
1821 {
1822 dl[i-1] = (ll[i]-ll[i-1])* (n-1)/(nnew-1);
1823 /* printf(" nbez[%d]:%f dl:%f\n", i-1, nbez[i-1], dl[i-1]); */
1824 }
1825 for (i=1; i<nnew; i++)
1826 {
1827 dlnew[i-1] = intpol( nbez, dl, n-1, (double)i/(double)(nnew-1)); /* i/(nnew-1) == nbeznew */
1828 /* fn+=dlnew[i-1]; */
1829 /* printf(" nbez[%d]:%f dlnew:%f\n", i-1,(double)i/(double)(nnew-1), dlnew[i-1]); */
1830 }
1831 /* for (i=1; i<nnew; i++) dlnew[i-1]*=ll[n-1]/fn; */
1832
1833 /* neue randkoordinaten */
1834 x[u*vmax +v] = lx[0];
1835 y[u*vmax +v] = ly[0];
1836 z[u*vmax +v] = lz[0];
1837 fn=dlnew[0];
1838 if (flag)
1839 {
1840 for (v=1; v<nnew-1; v++)
1841 {
1842 x[u*vmax +v] = intpol( ll, lx, n, fn );
1843 y[u*vmax +v] = intpol( ll, ly, n, fn );
1844 z[u*vmax +v] = intpol( ll, lz, n, fn );
1845 fn+=dlnew[v];
1846 }
1847 }
1848 else
1849 {
1850 for (u=1; u<umax-1; u++)
1851 {
1852 x[u*vmax +v] = intpol( ll, lx, n, fn );
1853 y[u*vmax +v] = intpol( ll, ly, n, fn );
1854 z[u*vmax +v] = intpol( ll, lz, n, fn );
1855 fn+=dlnew[u];
1856 }
1857 }
1858 x[u*vmax +v] = lx[n-1];
1859 y[u*vmax +v] = ly[n-1];
1860 z[u*vmax +v] = lz[n-1];
1861
1862 free(ll);
1863 free(dl);
1864 free(dlnew);
1865 free(nbez);
1866 return(1);
1867 }
1868
1869
1870
1871
1872 /*******************************************************************************************/
1873 /* splits line or lcmb at a certain position and returns 2 lines with nodes and elements */
1874 /* of the original one */
1875 /* in: */
1876 /* edge line or lcmb index */
1877 /* typ l for line or c for lcmb */
1878 /* splitdiv splitting location in terms of node-divisions */
1879 /* for example if the combined division of the lcmb is 10 then a value of .5 */
1880 /* would split the lcmb at node-position 6 and two lcmbs with div 5 are returned */
1881 /* out: */
1882 /* lnew 2 lines or lcmbs */
1883 /* typnew l for line or c for lcmb */
1884 /* returns -1 if failed or split-point-index if successfull */
1885 /*******************************************************************************************/
1886
splitLineAtDivratio(int edge,int typ,double splitdiv,int * lnew,char * typnew)1887 int splitLineAtDivratio(int edge, int typ, double splitdiv, int *lnew, char *typnew)
1888 {
1889 int c=0, i, j, l=0, n;
1890 int sum_div, div=0;
1891 int ps, cl=0, cnew[2];
1892 int seq[2], setNr;
1893 double v[3], p0[3], p1[3], p01[3], lbez, ps_lbez;
1894 char name[MAX_LINE_LENGTH];
1895 int *lin=NULL;
1896 char *ori=NULL;
1897
1898 double *pset_dl=NULL;
1899
1900
1901 /* define the split-point location and the line to split */
1902 if( typ=='l')
1903 {
1904 l= edge;
1905 if(line[l].div<2) return(-1);
1906 div=line[l].div*splitdiv-1;
1907 //printf("div:%d ld:%d spl:%d \n",div, line[l].div,splitdiv);
1908 if(div<0) return(-1);
1909 }
1910 else if( typ=='c')
1911 {
1912 if ((ori = (char *)realloc( (char *)ori, (lcmb[c].nl)*sizeof(char)) ) == NULL )
1913 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
1914 if ((lin = (int *)realloc( (int *)lin, (lcmb[c].nl)*sizeof(int)) ) == NULL )
1915 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
1916
1917 /* search the midspan line-index */
1918 c= edge;
1919 sum_div=div=0;
1920 for(i=0; i<lcmb[c].nl; i++)
1921 {
1922 l=lcmb[c].l[i];
1923 sum_div+=line[l].div;
1924 }
1925 for(i=0; i<lcmb[c].nl; i++)
1926 {
1927 l=lcmb[c].l[i];
1928 div+=line[l].div;
1929 if(div>sum_div*splitdiv) break;
1930 }
1931 cl=i;
1932 if(lcmb[c].o[cl]=='+') div=line[l].div-(div-sum_div*splitdiv)-1;
1933 else div=(div-sum_div*splitdiv)-1;
1934 }
1935
1936 /* check if the split-point would be at one of the ends of the line or if one line must be splitted */
1937 if(div==-1)
1938 {
1939 /* 1st Line-Point is the splitting point, no line must be splitted */
1940 ps=line[l].p1;
1941
1942 /* create two lcmb */
1943 if(lcmb[c].o[cl]=='+')
1944 {
1945 if(cl==0) return(-1);
1946 else if(cl==1)
1947 {
1948 lnew[0]=lcmb[c].l[0];
1949 typnew[0]='l';
1950 }
1951 else
1952 {
1953 for(i=0; i<cl; i++)
1954 {
1955 lin[i]=lcmb[c].l[i];
1956 ori[i]=lcmb[c].o[i];
1957 }
1958 getNewName( name, "c" );
1959 lnew[0]= lcmb_i( name, 0, i, ori, lin ); typnew[0]='c';
1960 pre_seta(specialset->zap, "c", name);
1961 }
1962
1963 if(cl==(lcmb[c].nl-1))
1964 {
1965 lnew[1]=lcmb[c].l[cl];
1966 typnew[1]='l';
1967 }
1968 else
1969 {
1970 for(i=cl; i<lcmb[c].nl; i++)
1971 {
1972 lin[i-cl]=lcmb[c].l[i];
1973 ori[i-cl]=lcmb[c].o[i];
1974 }
1975 getNewName( name, "c" );
1976 lnew[1]= lcmb_i( name, 0, i-cl, ori, lin ); typnew[1]='c';
1977 pre_seta(specialset->zap, "c", name);
1978 }
1979
1980 }
1981 else
1982 {
1983
1984 if(cl==0) { lnew[0]=lcmb[c].l[0]; typnew[0]='l'; }
1985 else
1986 {
1987 for(i=0; i<=cl; i++)
1988 {
1989 lin[i]=lcmb[c].l[i];
1990 ori[i]=lcmb[c].o[i];
1991 }
1992 getNewName( name, "c" );
1993 lnew[0]= lcmb_i( name, 0, i, ori, lin ); typnew[0]='c';
1994 pre_seta(specialset->zap, "c", name);
1995 }
1996
1997 if(cl==(lcmb[c].nl-1)) { lnew[1]=lcmb[c].l[cl]; typnew[1]='l'; }
1998 else
1999 {
2000 for(i=cl+1; i<lcmb[c].nl; i++)
2001 {
2002 lin[i-cl-1]=lcmb[c].l[i];
2003 ori[i-cl-1]=lcmb[c].o[i];
2004 }
2005 getNewName( name, "c" );
2006 lnew[1]= lcmb_i( name, 0, i-cl-1, ori, lin ); typnew[1]='c';
2007 pre_seta(specialset->zap, "c", name);
2008 }
2009
2010 }
2011 }
2012 else if(div==line[l].div-1)
2013 {
2014 /* last Line-Point is the splitting point, no line must be splitted */
2015 ps=line[l].p2;
2016
2017 /* create two lcmb */
2018 if(lcmb[c].o[cl]=='-')
2019 {
2020 if(cl==0) return(-1);
2021 else if(cl==1)
2022 {
2023 lnew[0]=lcmb[c].l[0];
2024 typnew[0]='l';
2025 }
2026 else
2027 {
2028 for(i=0; i<cl; i++)
2029 {
2030 lin[i]=lcmb[c].l[i];
2031 ori[i]=lcmb[c].o[i];
2032 }
2033 getNewName( name, "c" );
2034 lnew[0]= lcmb_i( name, 0, i, ori, lin ); typnew[0]='c';
2035 pre_seta(specialset->zap, "c", name);
2036 }
2037
2038 if(cl==(lcmb[c].nl-1))
2039 {
2040 lnew[1]=lcmb[c].l[cl];
2041 typnew[1]='l';
2042 }
2043 else
2044 {
2045 for(i=cl; i<lcmb[c].nl; i++)
2046 {
2047 lin[i-cl]=lcmb[c].l[i];
2048 ori[i-cl]=lcmb[c].o[i];
2049 }
2050 getNewName( name, "c" );
2051 lnew[1]= lcmb_i( name, 0, i-cl, ori, lin ); typnew[1]='c';
2052 pre_seta(specialset->zap, "c", name);
2053 }
2054
2055 }
2056 else
2057 {
2058
2059 if(cl==0) { lnew[0]=lcmb[c].l[0]; typnew[0]='l'; }
2060 else
2061 {
2062 for(i=0; i<=cl; i++)
2063 {
2064 lin[i]=lcmb[c].l[i];
2065 ori[i]=lcmb[c].o[i];
2066 }
2067 getNewName( name, "c" );
2068 lnew[0]= lcmb_i( name, 0, i, ori, lin ); typnew[0]='c';
2069 pre_seta(specialset->zap, "c", name);
2070 }
2071
2072 if(cl==(lcmb[c].nl-1)) { lnew[1]=lcmb[c].l[cl]; typnew[1]='l'; }
2073 else
2074 {
2075 for(i=cl+1; i<lcmb[c].nl; i++)
2076 {
2077 lin[i-cl-1]=lcmb[c].l[i];
2078 ori[i-cl-1]=lcmb[c].o[i];
2079 }
2080 getNewName( name, "c" );
2081 lnew[1]= lcmb_i( name, 0, i-cl-1, ori, lin ); typnew[1]='c';
2082 pre_seta(specialset->zap, "c", name);
2083 }
2084
2085 }
2086
2087 }
2088 else
2089 {
2090 /* create a splitting point */
2091 /* and two lines or lcmb */
2092
2093 if (line[l].typ=='a')
2094 {
2095 arcNodes( l, div, line[l].div, v );
2096 }
2097 else if (line[l].typ=='s')
2098 {
2099 splineNodes( l, div, line[l].div, v );
2100 }
2101 else
2102 {
2103 straightNodes( l, div, line[l].div, v );
2104 }
2105 n= getNewName( name, "p" );
2106 ps= pnt( name, v[0], v[1], v[2], 0 );
2107 pre_seta(specialset->zap, "p", name);
2108
2109
2110 /* create two lines/lcmbs out of the original one and apply the nodes/elements of the original */
2111
2112 /* create 2 new lines */
2113 if (line[l].typ=='a')
2114 {
2115 n= getNewName( name, "l" );
2116 lnew[0]= line_i( name, line[l].p1, ps, line[l].trk, div+1, 1, line[l].typ );
2117 if(lnew[0]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2118 pre_seta(specialset->zap, "l", name);
2119 n= getNewName( name, "l" );
2120 lnew[1]= line_i( name, ps, line[l].p2, line[l].trk, line[l].div-(div+1), 1, line[l].typ );
2121 if(lnew[1]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2122 pre_seta(specialset->zap, "l", name);
2123 }
2124 else if (line[l].typ=='s')
2125 {
2126 /* erzeuge zwei neue sets fuer die stuetzpunkte der zwei neuen linien */
2127 n= getNewName( name, "se" );
2128 seq[0]=pre_seta( name, "is", 0);
2129 if ( seq[0] <0 )
2130 { printf(" ERROR in splitLine\n"); return(-1); }
2131 pre_seta(specialset->zap, "r", name);
2132
2133 n= getNewName( name, "se" );
2134 seq[1]=pre_seta( name, "is", 0);
2135 if ( seq[1] <0 )
2136 { printf(" ERROR in splitLine\n"); return(-1); }
2137 pre_seta(specialset->zap, "r", name);
2138
2139 /* determine the length of the spline, accumulate all dists between points */
2140 /* look if the sequence is ordered in the same way as the line */
2141 setNr=line[l].trk;
2142 lbez=0.;
2143 if ( ( pset_dl= (double *)realloc( (double *)pset_dl, (set[setNr].anz_p+1) * sizeof(double))) == NULL )
2144 printf("ERROR: realloc failed: isort\n\n" );
2145 pset_dl[0]=0.;
2146 if( line[l].p1==set[setNr].pnt[0] )
2147 {
2148 p0[0]=point[set[setNr].pnt[0]].px;
2149 p0[1]=point[set[setNr].pnt[0]].py;
2150 p0[2]=point[set[setNr].pnt[0]].pz;
2151 for (i=1; i<set[setNr].anz_p; i++)
2152 {
2153 p1[0]=point[set[setNr].pnt[i]].px;
2154 p1[1]=point[set[setNr].pnt[i]].py;
2155 p1[2]=point[set[setNr].pnt[i]].pz;
2156 v_result( p0, p1, p01 );
2157 p0[0]=p1[0];
2158 p0[1]=p1[1];
2159 p0[2]=p1[2];
2160 lbez+=v_betrag( p01 );
2161 pset_dl[i]=lbez;
2162 }
2163 }
2164 else
2165 {
2166 p0[0]=point[set[setNr].pnt[set[setNr].anz_p-1]].px;
2167 p0[1]=point[set[setNr].pnt[set[setNr].anz_p-1]].py;
2168 p0[2]=point[set[setNr].pnt[set[setNr].anz_p-1]].pz;
2169 for (i=1; i<set[setNr].anz_p; i++)
2170 {
2171 p1[0]=point[set[setNr].pnt[set[setNr].anz_p-1-i]].px;
2172 p1[1]=point[set[setNr].pnt[set[setNr].anz_p-1-i]].py;
2173 p1[2]=point[set[setNr].pnt[set[setNr].anz_p-1-i]].pz;
2174 v_result( p0, p1, p01 );
2175 p0[0]=p1[0];
2176 p0[1]=p1[1];
2177 p0[2]=p1[2];
2178 lbez+=v_betrag( p01 );
2179 pset_dl[set[setNr].anz_p-1-i]=lbez;
2180 }
2181 }
2182 ps_lbez=lbez*splitdiv;
2183
2184 n=0;
2185 for (i=0; i<set[setNr].anz_p; i++)
2186 {
2187 if(pset_dl[i]<ps_lbez) seta( seq[0], "p", set[setNr].pnt[i] );
2188 else
2189 {
2190 if(!n){
2191 seta( seq[0], "p", ps );
2192 seta( seq[1], "p", ps ); n++; }
2193 /* add the spline point only if it is not co-incident with ps */
2194 if(pset_dl[i]>ps_lbez) seta( seq[1], "p", set[setNr].pnt[i] );
2195 }
2196 }
2197
2198 n= getNewName( name, "l" );
2199 lnew[0]= line_i( name, line[l].p1, ps, seq[0], div+1, 1, line[l].typ );
2200 if(lnew[0]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2201 pre_seta(specialset->zap, "l", name);
2202 n= getNewName( name, "l" );
2203 lnew[1]= line_i( name, ps, line[l].p2, seq[1], line[l].div-(div+1), 1, line[l].typ );
2204 if(lnew[1]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2205 pre_seta(specialset->zap, "l", name);
2206
2207 free(pset_dl);
2208 }
2209 else
2210 {
2211 n= getNewName( name, "l" );
2212 lnew[0]= line_i( name, line[l].p1, ps, -1, div+1, 1, line[l].typ );
2213 if(lnew[0]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2214 pre_seta(specialset->zap, "l", name);
2215 n= getNewName( name, "l" );
2216 lnew[1]= line_i( name, ps, line[l].p2, -1, line[l].div-(div+1), 1, line[l].typ );
2217 if(lnew[1]<0) { printf("ERROR: line could not be created\n"); return(-1); }
2218 pre_seta(specialset->zap, "l", name);
2219 }
2220 typnew[0]=typnew[1]='l';
2221
2222 if(line[l].nn)
2223 {
2224 /* map the nodes of the original line and additional point to the two new ones */
2225 if ((point[ps].nod = (int *)realloc( (int *)point[ps].nod, ((int)1)*sizeof(int)) ) == NULL )
2226 { printf(" ERROR: realloc failure in splitLineAtDivratio, point:%s can not be meshed\n\n", point[ps].name); return(-1); }
2227 point[ps].nod[0]=line[l].nod[div];
2228
2229 if(div>0)
2230 if ((line[lnew[0]].nod = (int *)realloc( (int *)line[lnew[0]].nod, (div)*sizeof(int)) ) == NULL )
2231 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[lnew[0]].name); return(-1); }
2232 for (i=0; i<div; i++)
2233 {
2234 line[lnew[0]].nod[i]=line[l].nod[i];
2235 }
2236 line[lnew[0]].nn=i;
2237
2238 if(line[l].div-2-div>0)
2239 if ((line[lnew[1]].nod = (int *)realloc( (int *)line[lnew[1]].nod, (line[l].div-2-div)*sizeof(int)) ) == NULL )
2240 { printf(" ERROR: realloc failure in meshLines Line:%s can not be meshed\n\n", line[lnew[0]].name); return(-1); }
2241 j=0;
2242 for (i=div+1; i<line[l].div-1; i++)
2243 {
2244 line[lnew[1]].nod[j]=line[l].nod[i];
2245 j++;
2246 }
2247 line[lnew[1]].nn=j;
2248 }
2249
2250 /* change lnew if the edge is an lcmb */
2251 if( typ=='c')
2252 {
2253 if(lcmb[c].o[cl]=='-')
2254 {
2255 cnew[0]=lnew[1];
2256 cnew[1]=lnew[0];
2257 lnew[0]=cnew[0];
2258 lnew[1]=cnew[1];
2259 }
2260 if(cl>0)
2261 {
2262 for(i=0; i<cl; i++)
2263 {
2264 lin[i]=lcmb[c].l[i];
2265 ori[i]=lcmb[c].o[i];
2266 }
2267 lin[i]=lnew[0];
2268 ori[i]=lcmb[c].o[cl];
2269 getNewName( name, "c" );
2270 lnew[0]= lcmb_i( name, 0, i+1, ori, lin ); typnew[0]='c';
2271 pre_seta(specialset->zap, "c", name);
2272 }
2273
2274 if(cl<lcmb[c].nl-1)
2275 {
2276 lin[0]=lnew[1];
2277 ori[0]=lcmb[c].o[cl];
2278 j=1;
2279 for(i=cl+1; i<lcmb[c].nl; i++)
2280 {
2281 lin[j]=lcmb[c].l[i];
2282 ori[j]=lcmb[c].o[i];
2283 j++;
2284 }
2285 getNewName( name, "c" );
2286 lnew[1]= lcmb_i( name, 0, j, ori, lin ); typnew[1]='c';
2287 pre_seta(specialset->zap, "c", name);
2288 }
2289 }
2290
2291 }
2292 free(lin);
2293 free(ori);
2294 return(ps);
2295 }
2296
2297
2298 /* creates a lcmb out of two lines or lcmbs */
2299 /* returns index of an lcmb or -1 if failed */
addTwoLines(int l1,char o1,char typ1,int l2,char o2,char typ2)2300 int addTwoLines( int l1, char o1, char typ1, int l2, char o2, char typ2 )
2301 {
2302 int i, j, c, *lin;
2303 char name[MAX_LINE_LENGTH], *ori;
2304
2305 if((typ1=='l')&&(typ2=='l'))
2306 {
2307 if ((ori = (char *)malloc((2)*sizeof(char)) ) == NULL )
2308 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2309 if ((lin = (int *)malloc((2)*sizeof(int)) ) == NULL )
2310 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2311 lin[0]=l1;
2312 ori[0]=o1;
2313 lin[1]=l2;
2314 ori[1]=o2;
2315 getNewName( name, "c" );
2316 c = lcmb_i( name, 0, 2, ori, lin );
2317 pre_seta(specialset->zap, "c", name);
2318 free(ori); free(lin);
2319 }
2320 else if((typ1=='l')&&(typ2=='c'))
2321 {
2322 if ((ori = (char *)malloc((lcmb[l2].nl+1)*sizeof(char)) ) == NULL )
2323 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2324 if ((lin = (int *)malloc((lcmb[l2].nl+1)*sizeof(int)) ) == NULL )
2325 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2326 lin[0]=l1;
2327 ori[0]=o1;
2328 j=1;
2329 if(o2=='+')
2330 {
2331 for( i=0; i<lcmb[l2].nl; i++)
2332 {
2333 lin[j]=lcmb[l2].l[i];
2334 ori[j]=lcmb[l2].o[i];
2335 j++;
2336 }
2337 }
2338 else
2339 {
2340 for( i=lcmb[l2].nl-1; i>=0; i--)
2341 {
2342 lin[j]=lcmb[l2].l[i];
2343 ori[j]=lcmb[l2].o[i];
2344 j++;
2345 }
2346 }
2347 getNewName( name, "c" );
2348 c = lcmb_i( name, 0, j, ori, lin );
2349 pre_seta(specialset->zap, "c", name);
2350 free(ori); free(lin);
2351 }
2352 else if((typ1=='c')&&(typ2=='l'))
2353 {
2354 if ((ori = (char *)malloc((lcmb[l1].nl+1)*sizeof(char)) ) == NULL )
2355 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2356 if ((lin = (int *)malloc((lcmb[l1].nl+1)*sizeof(int)) ) == NULL )
2357 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2358 j=0;
2359 if(o1=='+')
2360 {
2361 for( i=0; i<lcmb[l1].nl; i++)
2362 {
2363 lin[j]=lcmb[l1].l[i];
2364 ori[j]=lcmb[l1].o[i];
2365 j++;
2366 }
2367 }
2368 else
2369 {
2370 for( i=lcmb[l1].nl-1; i>=0; i--)
2371 {
2372 lin[j]=lcmb[l1].l[i];
2373 ori[j]=lcmb[l1].o[i];
2374 j++;
2375 }
2376 }
2377 lin[j]=l2;
2378 ori[j]=o2;
2379 j++;
2380 getNewName( name, "c" );
2381 c = lcmb_i( name, 0, j, ori, lin );
2382 pre_seta(specialset->zap, "c", name);
2383 free(ori); free(lin);
2384 }
2385 else if((typ1=='c')&&(typ2=='c'))
2386 {
2387 if ((ori = (char *)malloc((lcmb[l1].nl+lcmb[l2].nl)*sizeof(char)) ) == NULL )
2388 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2389 if ((lin = (int *)malloc((lcmb[l1].nl+lcmb[l2].nl)*sizeof(int)) ) == NULL )
2390 { printf("\n\nERROR: realloc failure in splitLineAtDivratio\n\n"); return(-1); }
2391 j=0;
2392 if(o1=='+')
2393 {
2394 for( i=0; i<lcmb[l1].nl; i++)
2395 {
2396 lin[j]=lcmb[l1].l[i];
2397 ori[j]=lcmb[l1].o[i];
2398 j++;
2399 }
2400 }
2401 else
2402 {
2403 for( i=lcmb[l1].nl-1; i>=0; i--)
2404 {
2405 lin[j]=lcmb[l1].l[i];
2406 ori[j]=lcmb[l1].o[i];
2407 j++;
2408 }
2409 }
2410 if(o2=='+')
2411 {
2412 for( i=0; i<lcmb[l2].nl; i++)
2413 {
2414 lin[j]=lcmb[l2].l[i];
2415 ori[j]=lcmb[l2].o[i];
2416 j++;
2417 }
2418 }
2419 else
2420 {
2421 for( i=lcmb[l2].nl-1; i>=0; i--)
2422 {
2423 lin[j]=lcmb[l2].l[i];
2424 ori[j]=lcmb[l2].o[i];
2425 j++;
2426 }
2427 }
2428 getNewName( name, "c" );
2429 c = lcmb_i( name, 0, j, ori, lin );
2430 pre_seta(specialset->zap, "c", name);
2431 free(ori); free(lin);
2432 }
2433 else return(-1);
2434 return(c);
2435 }
2436
2437
calcMeshDistance(int nr,int np,Points * ppre,int e,Points * pcg,int * tri)2438 double calcMeshDistance( int nr, int np, Points *ppre, int e, Points *pcg, int *tri)
2439 {
2440 int i,j,k,n;
2441 int n1,n2, flag;
2442 double vl[3],dist;
2443 double clength, dist_length, dist_maxlength;
2444 Points *cg=NULL;
2445
2446 typedef struct {
2447 int sum, *n2;
2448 double *l;
2449 }N1l;
2450 N1l *n1l=NULL;
2451
2452 /* decrement the pointer, tri[0] points to ppre[1] */
2453 ppre--;
2454
2455 /* determine the distance of the cg of all tri to the nurbs,
2456 calc the ratio of this distance to the circumferential length of the tri as a quality measure
2457 */
2458
2459 /* scan all tri and calc the cg and their circum. length (clength) */
2460 /* calc the length of all edges and reference them by its nodes */
2461
2462 if ( (n1l = (N1l *)malloc( (np+1) * sizeof(N1l))) == NULL )
2463 { printf("\n\n ERROR in calcMeshDistance: malloc\n\n") ; return(0.); }
2464 for (i=0; i<=np; i++)
2465 {
2466 n1l[i].sum=0;
2467 n1l[i].n2=NULL;
2468 n1l[i].l=NULL;
2469 }
2470
2471 if( (cg = (Points *)calloc((e),sizeof(Points) )) == NULL )
2472 { printf(" ERROR: malloc failure\n\n"); return(-1); }
2473
2474 j=0;
2475 dist_maxlength=0.;
2476 for(i=0; i<e; i++)
2477 {
2478 /* check if the length is not known */
2479 clength=0.;
2480
2481 for(n=0; n<3; n++)
2482 {
2483 if(n==0)
2484 {
2485 n1=tri[j];
2486 n2=tri[j+1];
2487 }
2488 else if(n==1)
2489 {
2490 n1=tri[j+1];
2491 n2=tri[j+2];
2492 }
2493 else
2494 {
2495 n1=tri[j+2];
2496 n2=tri[j];
2497 }
2498
2499 flag=1;
2500 for(k=0; k<n1l[n1].sum; k++)
2501 {
2502 if(n1l[n1].n2[k]==n2) { clength+=n1l[n1].l[k]; flag=0; break; }
2503 }
2504 if(flag==1)
2505 {
2506 v_result(&ppre[n1].px,&ppre[n2].px,vl);
2507
2508 if ( (n1l[n2].n2 = (int *)realloc( n1l[n2].n2, (n1l[n2].sum+1) * sizeof(int))) == NULL )
2509 { printf("\n\n ERROR in realloc\n\n") ; return(0.); }
2510 if ( (n1l[n2].l = (double *)realloc( n1l[n2].l, (n1l[n2].sum+1) * sizeof(double))) == NULL )
2511 { printf("\n\n ERROR in realloc\n\n") ; return(0.); }
2512 n1l[n2].n2[n1l[n2].sum]=n1;
2513 n1l[n2].l[n1l[n2].sum]=v_betrag(vl);
2514 clength+=n1l[n2].l[n1l[n2].sum];
2515 n1l[n2].sum++;
2516 }
2517 }
2518
2519 for(n=0; n<3; n++)
2520 {
2521 cg[i].px+=ppre[tri[j+n]].px;
2522 cg[i].py+=ppre[tri[j+n]].py;
2523 cg[i].pz+=ppre[tri[j+n]].pz;
2524 }
2525 cg[i].px/=3.;
2526 cg[i].py/=3.;
2527 cg[i].pz/=3.;
2528 j+=3;
2529
2530 /* determine the distance of the cg at the nurbs to the cg of the tri in xyz */
2531 v_result(&cg[i].px,&pcg[i].px,vl);
2532 dist=v_betrag(vl);
2533 /* calc the ratio */
2534 dist_length=dabs(dist)/clength;
2535 if(dist_length>dist_maxlength) dist_maxlength=dist_length;
2536 }
2537
2538 for (i=0; i<=np; i++) { free(n1l[i].n2); free(n1l[i].l); }
2539 free(n1l);
2540 free(cg);
2541
2542 return(dist_maxlength);
2543 }
2544
2545
2546 /* ppre real coordinates of tri-nodes */
triSplitter(int nr,int * ptr_np,Points ** ptr_ppre,int * ptr_ne,int ** ptr_tri,int ** ptr_pntflag,int ** edge_n2,int * pnt_indx,double ** ptr_pntu,double ** ptr_pntv,double max_ratio,double * tab_u,double * tab_lu,double * tab_bu,double * tab_v,double * tab_lv,double * tab_bv)2547 int triSplitter( int nr, int *ptr_np, Points **ptr_ppre, int *ptr_ne, int **ptr_tri, int **ptr_pntflag, int **edge_n2, int *pnt_indx, double **ptr_pntu, double **ptr_pntv, double max_ratio, double *tab_u, double *tab_lu, double *tab_bu, double *tab_v, double *tab_lv, double *tab_bv)
2548 {
2549 int i,k,n,loop=0;
2550 int e,n1,n2,nm, nmp=0, continueFlag=0, nurbsType;
2551 Points *pm=NULL,*pm2=NULL,*nv=NULL, *ppre;
2552 int np,ne, *tri;
2553 double p1p2[3], pbuf[3], u=0.5;
2554 double *pntm_u=NULL, *pntm_v=NULL, *dist=NULL, *ln1n2=NULL;
2555 double *pnt_u, *pnt_v;
2556 double pnt_uscal[2], pnt_vscal[2], bu[2],bv[2],sumbu,sumbv;
2557 int n_nm[3],edge_nm[3],sum_nm=0,e_buf, *pnt_flag;
2558
2559 typedef struct {
2560 int sum, *n2, *nm;
2561 }N1nm;
2562 N1nm *n1nm=NULL;
2563
2564 typedef struct {
2565 int mod[3], nc[3], nm[3];
2566 }Tribuf;
2567 Tribuf *tribuf=NULL;
2568
2569 np=*ptr_np;
2570 ppre=*ptr_ppre;
2571 ne=*ptr_ne;
2572 tri=*ptr_tri;
2573 pnt_flag=*ptr_pntflag;
2574 pnt_u=*ptr_pntu;
2575 pnt_v=*ptr_pntv;
2576
2577 sem_wait(&sem_g);
2578 nurbsType=nurbs[nr].nurbsType;
2579 sem_post(&sem_g);
2580
2581 /* In case its a curved surface, the triangles are splitted like tr6.
2582 The distance to the nurbs is then determined for the additional points.
2583 If a point is too far away it is set to the nurbs and used for new tr3.
2584 The original tr3 is redefined as one of the new tr3's.
2585 The procedere is repeated until no violation of the criterion appears or if the smallest tri is below a threshold-value
2586
2587 tribuf[tri].nm[3]: temporary midnode, index of new field called pms
2588 .nc[3]: corner-node, (nm[x] follows nc[x] in the tri )
2589 .mod[3]: 1= was too far away from nurbs and triggers new tri's
2590
2591 Remark:
2592 the node-nr referenced from tri[] is the index+1 from ppre[]: ppre[tri[]-1] !
2593 */
2594
2595 /* loop until the tris are close enough */
2596 for(loop=0; loop<MAX_MESH2D_LOOPS; loop++)
2597 {
2598 //printf("hallo loop%d ne:%d np:%d\n", loop, ne, np);
2599 /* create new nodes in the middle of each edge except the boundary edges (as with "mids <set> gen" )*/
2600 /* and calculate real world coords in the middle of the edges (pms) */
2601
2602 /* create a table for all nodes which points to already created midside nodes */
2603 if ( (n1nm = (N1nm *)malloc( (np+1) * sizeof(N1nm))) == NULL )
2604 { printf("\n\n ERROR in triSplitter: malloc\n\n") ; return(-1); }
2605 for (i=0; i<=np; i++) n1nm[i].sum=0;
2606 for (i=0; i<=np; i++) n1nm[i].n2=n1nm[i].nm=NULL;
2607
2608 if ( (tribuf = (Tribuf *)realloc(tribuf, (ne) * sizeof(Tribuf))) == NULL )
2609 { printf("\n\n ERROR in triSplitter: malloc\n\n"); return(-1); }
2610
2611 nmp=e=0;
2612 for (k=0; k<ne; k++)
2613 {
2614 for (n=0; n<3; n++)
2615 {
2616 tribuf[k].mod[n]=0;
2617 tribuf[k].nc[n]= n1=tri[e+n];
2618 if(n<2) n2=tri[e+n+1];
2619 else n2=tri[e];
2620 //printf("hallo n1:%d n2:%d e:%d pnt_flag: %d %d\n",n1, n2, k, pnt_flag[n1-1], pnt_flag[n2-1]);
2621
2622 // check if its a boundary edge then no split-node has to be created
2623 if((pnt_flag[n1-1]!=0)&&(pnt_flag[n2-1]!=0))
2624 {
2625 // check if n1+n2 are a bounday edge
2626 //printf("n1-1:%d n2-1:%d\n", n1-1,n2-1);
2627 //printf("pnt_indx[n1-1]:%d pnt_indx[n2-1]:%d\n", pnt_indx[n1-1],pnt_indx[n2-1]);
2628 if(edge_n2[pnt_indx[n1-1]][0]==pnt_indx[n2-1]) { tribuf[k].nm[n]=-1; continue; }
2629 else if(edge_n2[pnt_indx[n1-1]][1]==pnt_indx[n2-1]) { tribuf[k].nm[n]=-1; continue; }
2630 }
2631
2632 // check if the nm exists already
2633 nm=-1;
2634 for(i=0; i<n1nm[n1].sum; i++) if(n1nm[n1].n2[i]==n2) nm=n1nm[n1].nm[i];
2635 for(i=0; i<n1nm[n2].sum; i++) if(n1nm[n2].n2[i]==n1) nm=n1nm[n2].nm[i];
2636
2637 if(nm==-1)
2638 {
2639 // generate new midside-point
2640 if( (pm = (Points *)realloc(pm, (nmp+1)*sizeof(Points) )) == NULL )
2641 { printf(" ERROR: malloc failure\n\n");
2642 return(-1); }
2643 if( (pntm_u = (double *)realloc(pntm_u, (nmp+1)*sizeof(double) )) == NULL )
2644 { printf(" ERROR: malloc failure\n\n");
2645 return(-1); }
2646 if( (pntm_v = (double *)realloc(pntm_v, (nmp+1)*sizeof(double) )) == NULL )
2647 { printf(" ERROR: malloc failure\n\n");
2648 return(-1); }
2649 // store the length between n1 and n2
2650 if( (ln1n2 = (double *)realloc(ln1n2, (nmp+1)*sizeof(double) )) == NULL )
2651 { printf(" ERROR: malloc failure\n\n");
2652 return(-1); }
2653 nm=nmp;
2654 nmp++;
2655
2656 // real world coords
2657 v_result( &ppre[n1-1].px, &ppre[n2-1].px, p1p2 );
2658 ln1n2[nm] =v_betrag(p1p2 );
2659 v_scal( &u, p1p2, pbuf);
2660 if(nurbsType<=20)
2661 {
2662 if( (pm2 = (Points *)realloc(pm2, (nmp+1)*sizeof(Points) )) == NULL )
2663 { printf(" ERROR: malloc failure\n\n"); return(-1); }
2664 v_add( &ppre[n1-1].px, pbuf, &pm2[nm].px);
2665 }
2666 else
2667 {
2668 v_add( &ppre[n1-1].px, pbuf, &pm[nm].px);
2669 }
2670 pm[nm].name=(char *)0;
2671
2672 // parametric coords for the mid node (uv)
2673 /*
2674 // alternatively w/o scaling:
2675 pntm_u[nm]=(pnt_u[n1-1]+pnt_u[n2-1])*.5;
2676 pntm_v[nm]=(pnt_v[n1-1]+pnt_v[n2-1])*.5;
2677 printf(" node %d %f %f %f\n", nm, pntm_u[nm],pntm_v[nm],0.);
2678 */
2679 pnt_uscal[0]=intpol( tab_u, tab_lu, UV_STEPS, pnt_u[n1-1] );
2680 pnt_vscal[0]=intpol( tab_v, tab_lv, UV_STEPS, pnt_v[n1-1] );
2681 pnt_uscal[1]=intpol( tab_u, tab_lu, UV_STEPS, pnt_u[n2-1] );
2682 pnt_vscal[1]=intpol( tab_v, tab_lv, UV_STEPS, pnt_v[n2-1] );
2683 bu[0]=intpol( tab_u, tab_bu, UV_STEPS, pnt_u[n1-1] );
2684 bv[0]=intpol( tab_v, tab_bv, UV_STEPS, pnt_v[n1-1] );
2685 bu[1]=intpol( tab_u, tab_bu, UV_STEPS, pnt_u[n2-1] );
2686 bv[1]=intpol( tab_v, tab_bv, UV_STEPS, pnt_v[n2-1] );
2687 sumbu=bu[0]+bu[1];
2688 sumbv=bv[0]+bv[1];
2689 pntm_u[nm]=pnt_uscal[0]*(bv[0]/sumbv)+pnt_uscal[1]*(bv[1]/sumbv);
2690 pntm_v[nm]=pnt_vscal[0]*(bu[0]/sumbu)+pnt_vscal[1]*(bu[1]/sumbu);
2691 pntm_u[nm]=intpol( tab_lu, tab_u, UV_STEPS, pntm_u[nm]);
2692 pntm_v[nm]=intpol( tab_lv, tab_v, UV_STEPS, pntm_v[nm]);
2693 //printf(" # %f %f %f %f %f %f\n", bu[0],bv[0],bu[1],bv[1],sumbu,sumbv);
2694 //printf(" node %d %f %f %f\n", nm, pntm_u[nm],pntm_v[nm],0.);
2695
2696 if ( (n1nm[n1].n2 = (int *)realloc( n1nm[n1].n2, (n1nm[n1].sum+1) * sizeof(int))) == NULL )
2697 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
2698 if ( (n1nm[n1].nm = (int *)realloc( n1nm[n1].nm, (n1nm[n1].sum+1) * sizeof(int))) == NULL )
2699 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
2700 n1nm[n1].n2[n1nm[n1].sum]=n2;
2701 n1nm[n1].nm[n1nm[n1].sum]=nm;
2702 n1nm[n1].sum++;
2703 }
2704 tribuf[k].nm[n]=nm;
2705 }
2706 e+=3;
2707 }
2708 for (i=0; i<=np; i++) { free(n1nm[i].n2); free(n1nm[i].nm); }
2709 free(n1nm);
2710
2711 /* determine the distance between pm and the nurbs */
2712 //for(i=0; i<nmp; i++) printf("hallo %d pm:%f %f %f \n",i, pm2[i].px, pm2[i].py, pm2[i].pz);
2713 /* calculate real world coordinates based on uv */
2714 if( (nv = (Points *)realloc(nv, (nmp)*sizeof(Points) )) == NULL )
2715 { printf(" ERROR: malloc failure\n\n"); return(-1); }
2716 evalNurbsWithNormalVector( nr, nmp, pntm_u, pntm_v, pm, nv);
2717
2718 /* calc the distance between pm and rw-pm2 in the direction of the normal vector */
2719 if( (dist = (double *)realloc(dist, (nmp)*sizeof(double) )) == NULL )
2720 { printf(" ERROR: malloc failure\n\n");
2721 return(-1); }
2722 for (i=0; i<nmp; i++)
2723 {
2724 p1p2[0]=pm2[i].px-pm[i].px;
2725 p1p2[1]=pm2[i].py-pm[i].py;
2726 p1p2[2]=pm2[i].pz-pm[i].pz;
2727 v_norm( &nv[i].px, pbuf);
2728 dist[i]=dabs(v_sprod( p1p2, pbuf));
2729 }
2730 free(nv); nv=NULL;
2731
2732 /*
2733 for(i=0; i<nmp; i++) { printf("#hallo %d dist:%lf pm:%f %f %f \n",i,dist[i], pm[i].px, pm[i].py, pm[i].pz);
2734 printf(" pnt pm2%d %f %f %f\n",i, pm2[i].px* scale->w+scale->x, pm2[i].py* scale->w+scale->y, pm2[i].pz* scale->w+scale->z);
2735 printf(" pnt pm%d %f %f %f\n",i, pm[i].px* scale->w+scale->x, pm[i].py* scale->w+scale->y, pm[i].pz* scale->w+scale->z);
2736 }
2737 */
2738
2739 /* set tribuf[].mod[] to 1 if the related pm is too far away from the nurbs and the tri has to be splitted. This is measured as dist/ln1n2 */
2740 /* experimentally it was modified to (dist/ln1n2) *TRISPLITTER_QUALITY_THRESHOLD_FACTOR */
2741 for (k=0; k<ne; k++)
2742 {
2743 for (n=0; n<3; n++)
2744 {
2745 nm=tribuf[k].nm[n];
2746 if((nm!=-1)&&(dist[nm]/ln1n2[nm]*TRISPLITTER_QUALITY_THRESHOLD_FACTOR > max_ratio)) tribuf[k].mod[n]=1;
2747 }
2748 }
2749
2750 /* go over all boundary nodes and set related tribuf[].mod[] back to 0 (no new tri's at the boundary) */
2751 continueFlag=0;
2752 for (k=0; k<ne; k++)
2753 {
2754 for (n=0; n<3; n++)
2755 {
2756 // check if still one edge has to be splitted
2757 if(tribuf[k].mod[n]) continueFlag=1;
2758 }
2759 }
2760 if(!continueFlag) goto finishLoop;
2761
2762 /* create additional ppre based on pms */
2763 for (k=0; k<ne; k++)
2764 {
2765 for (n=0; n<3; n++)
2766 {
2767 i=tribuf[k].nm[n];
2768 if(tribuf[k].mod[n])
2769 {
2770 pm[i].name=(char *)1;
2771 //printf(" pnt p%d %f %f %f\n",i, pm[i].px* scale->w+scale->x, pm[i].py* scale->w+scale->y, pm[i].pz* scale->w+scale->z);
2772 }
2773 }
2774 }
2775 for (i=0; i<nmp; i++)
2776 {
2777 if(pm[i].name==(char *)1)
2778 {
2779 //printf("hallo new point %d from %d\n",np,i);
2780 if( (ppre = (Points *)realloc(ppre, (np+1)*sizeof(Points) )) == NULL )
2781 { printf(" ERROR: malloc failure\n\n"); return(-1); }
2782 if( (pnt_flag = (int *)realloc(pnt_flag, (np+1)*sizeof(int) )) == NULL )
2783 { printf(" ERROR: malloc failure\n\n"); return(-1); }
2784 if( (pnt_u = (double *)realloc(pnt_u, (np+1)*sizeof(double) )) == NULL )
2785 { printf(" ERROR: malloc failure\n\n");
2786 return(-1); }
2787 if( (pnt_v = (double *)realloc(pnt_v, (np+1)*sizeof(double) )) == NULL )
2788 { printf(" ERROR: malloc failure\n\n");
2789 return(-1); }
2790 ppre[np].px=pm[i].px;
2791 ppre[np].py=pm[i].py;
2792 ppre[np].pz=pm[i].pz;
2793 pnt_u[np]=pntm_u[i];
2794 pnt_v[np]=pntm_v[i];
2795 pnt_flag[np] = 0;
2796 np++;
2797 pm[i].nn=np;
2798 }
2799 }
2800
2801 /* redefine and create new tri, pnt_u, pnt_v if tribuf[].mod[]==1 */
2802 /* go over all tribuf and look for moved midnodes */
2803 e_buf=ne;
2804 for(k=0; k<e_buf; k++)
2805 {
2806 // edge_nm: stores index of moved mid-node pms from tribuf
2807 // sum_nm: stores number of moved nodes per tribuf
2808 // n_nm : new node
2809 sum_nm=0;
2810 for(n=0; n<3; n++) if(tribuf[k].mod[n]==1) { edge_nm[sum_nm]=n; n_nm[sum_nm]=pm[tribuf[k].nm[n]].nn; sum_nm++; }
2811
2812 if( (tri = (int *)realloc((int *)tri, ((ne+sum_nm)*3)*sizeof(int) )) == NULL )
2813 { printf(" ERROR: realloc failure\n\n"); return(-1); }
2814
2815 switch(sum_nm)
2816 {
2817 // one node moved, redefine orig tri and create 1 new tri
2818 case 1:
2819 switch(edge_nm[0])
2820 {
2821 case 0:
2822 tri[k*3]=tribuf[k].nc[0];
2823 tri[k*3+1]= n_nm[0];
2824 tri[k*3+2]=tribuf[k].nc[2];
2825 tri[ne*3]= n_nm[0];
2826 tri[ne*3+1]=tribuf[k].nc[1];
2827 tri[ne*3+2]=tribuf[k].nc[2];
2828 break;
2829 case 1:
2830 tri[k*3]=tribuf[k].nc[0];
2831 tri[k*3+1]=tribuf[k].nc[1];
2832 tri[k*3+2]= n_nm[0];
2833 tri[ne*3]= n_nm[0];
2834 tri[ne*3+1]=tribuf[k].nc[2];
2835 tri[ne*3+2]=tribuf[k].nc[0];
2836 break;
2837 case 2:
2838 tri[k*3]=tribuf[k].nc[0];
2839 tri[k*3+1]=tribuf[k].nc[1];
2840 tri[k*3+2]= n_nm[0];
2841 tri[ne*3]= n_nm[0];
2842 tri[ne*3+1]=tribuf[k].nc[1];
2843 tri[ne*3+2]=tribuf[k].nc[2];
2844 break;
2845 }
2846 ne++;
2847 break;
2848
2849 // two nodes moved, redefine orig tri and create 2 new tris
2850 case 2:
2851 switch(edge_nm[0])
2852 {
2853 case 0:
2854 switch(edge_nm[1])
2855 {
2856 case 1:
2857 tri[k*3]=tribuf[k].nc[0];
2858 tri[k*3+1]= n_nm[0];
2859 tri[k*3+2]=tribuf[k].nc[2];
2860 tri[ne*3]= tribuf[k].nc[2];
2861 tri[ne*3+1]=n_nm[0];
2862 tri[ne*3+2]=n_nm[1];
2863 ne++;
2864 tri[ne*3]= n_nm[1];
2865 tri[ne*3+1]=n_nm[0];
2866 tri[ne*3+2]=tribuf[k].nc[1];
2867 break;
2868 case 2:
2869 tri[k*3]=tribuf[k].nc[0];
2870 tri[k*3+1]= n_nm[0];
2871 tri[k*3+2]= n_nm[1];
2872 tri[ne*3]= n_nm[1];
2873 tri[ne*3+1]= n_nm[0];
2874 tri[ne*3+2]=tribuf[k].nc[2];
2875 ne++;
2876 tri[ne*3]=tribuf[k].nc[2];
2877 tri[ne*3+1]=n_nm[0];
2878 tri[ne*3+2]=tribuf[k].nc[1];
2879 break;
2880 }
2881 break;
2882
2883 case 1:
2884 switch(edge_nm[1])
2885 {
2886 case 0:
2887 tri[k*3]=tribuf[k].nc[0];
2888 tri[k*3+1]= n_nm[1];
2889 tri[k*3+2]=tribuf[k].nc[2];
2890 tri[ne*3]= tribuf[k].nc[2];
2891 tri[ne*3+1]=n_nm[1];
2892 tri[ne*3+2]=n_nm[0];
2893 ne++;
2894 tri[ne*3]= n_nm[0];
2895 tri[ne*3+1]=n_nm[1];
2896 tri[ne*3+2]=tribuf[k].nc[1];
2897 break;
2898 case 2:
2899 tri[k*3]=tribuf[k].nc[1];
2900 tri[k*3+1]= n_nm[0];
2901 tri[k*3+2]=tribuf[k].nc[0];
2902 tri[ne*3]= tribuf[k].nc[0];
2903 tri[ne*3+1]=n_nm[0];
2904 tri[ne*3+2]=n_nm[1];
2905 ne++;
2906 tri[ne*3]= n_nm[1];
2907 tri[ne*3+1]=n_nm[0];
2908 tri[ne*3+2]=tribuf[k].nc[2];
2909 break;
2910 }
2911 break;
2912
2913 case 2:
2914 switch(edge_nm[1])
2915 {
2916 case 0:
2917 tri[k*3]=tribuf[k].nc[0];
2918 tri[k*3+1]= n_nm[1];
2919 tri[k*3+2]= n_nm[0];
2920 tri[ne*3]= n_nm[0];
2921 tri[ne*3+1]= n_nm[1];
2922 tri[ne*3+2]=tribuf[k].nc[2];
2923 ne++;
2924 tri[ne*3]=tribuf[k].nc[2];
2925 tri[ne*3+1]=n_nm[1];
2926 tri[ne*3+2]=tribuf[k].nc[1];
2927 break;
2928 case 1:
2929 tri[k*3]=tribuf[k].nc[1];
2930 tri[k*3+1]= n_nm[1];
2931 tri[k*3+2]=tribuf[k].nc[0];
2932 tri[ne*3]= tribuf[k].nc[0];
2933 tri[ne*3+1]=n_nm[1];
2934 tri[ne*3+2]=n_nm[0];
2935 ne++;
2936 tri[ne*3]= n_nm[0];
2937 tri[ne*3+1]=n_nm[1];
2938 tri[ne*3+2]=tribuf[k].nc[2];
2939 break;
2940 }
2941 break;
2942 }
2943 ne++;
2944 break;
2945
2946 // three nodes moved, redefine orig tri and create 3 new tris
2947 case 3:
2948 //printf("ERROR: the case with 3 splitnodes are not included so far\n");
2949 //exit(0);
2950 tri[k*3]=tribuf[k].nc[0];
2951 tri[k*3+1]= n_nm[0];
2952 tri[k*3+2]= n_nm[2];
2953 tri[ne*3]= n_nm[2];
2954 tri[ne*3+1]= n_nm[0];
2955 tri[ne*3+2]=n_nm[1];
2956 ne++;
2957 tri[ne*3]=n_nm[1];
2958 tri[ne*3+1]=n_nm[0];
2959 tri[ne*3+2]=tribuf[k].nc[1];
2960 ne++;
2961 tri[ne*3]=n_nm[2];
2962 tri[ne*3+1]=n_nm[1];
2963 tri[ne*3+2]=tribuf[k].nc[2];
2964 ne++;
2965 break;
2966 }
2967 }
2968 /*
2969 printf("*NODE\n");
2970 for (i=0; i<np; i++)
2971 {
2972 printf("%d, %f, %f, %f\n",i+1, ppre[i].px* scale->w+scale->x, ppre[i].py* scale->w+scale->y, ppre[i].pz* scale->w+scale->z);
2973 }
2974 printf("*ELEMENT, TYPE=S3R, ELSET=Eall\n");
2975 for (k=0; k<ne; k++)
2976 //for (k=0; k<1; k++)
2977 {
2978 printf("%d, %d, %d, %d\n",k+1, tri[k*3], tri[k*3+1], tri[k*3+2]);
2979 }
2980 */
2981
2982 finishLoop:;
2983 free(pm); pm=NULL;
2984 free(pm2); pm2=NULL;
2985 free(pntm_u); pntm_u=NULL;
2986 free(pntm_v); pntm_v=NULL;
2987 free(tribuf); tribuf=NULL;
2988 if(nurbsType<=20) { free(dist); dist=NULL; }
2989 else cppfreearray(dist);
2990 free(ln1n2); ln1n2=NULL;
2991 if(!continueFlag) break;
2992 }
2993 *ptr_np=np;
2994 *ptr_ppre=ppre;
2995 *ptr_ne=ne;
2996 *ptr_tri=tri;
2997 *ptr_pntflag=pnt_flag;
2998 *ptr_pntu=pnt_u;
2999 *ptr_pntv=pnt_v;
3000
3001 return(1);
3002 }
3003
3004
3005
checkMesh(int np,Points * ppre,int e,int * tri)3006 int checkMesh(int np, Points *ppre, int e, int *tri)
3007 {
3008 int i,j,n;
3009 double p0[3], p0p1[3], p2p0[3], p1p2[3], p1[3], p2[3], sp[3];
3010
3011 /* decrement the pointer, tri[0] points to ppre[1] */
3012 ppre--;
3013
3014 j=0;
3015 for(i=0; i<e; i++)
3016 {
3017 v_result(&ppre[tri[j]].px,&ppre[tri[j+1]].px,p0p1);
3018 v_result(&ppre[tri[j+1]].px,&ppre[tri[j+2]].px,p1p2);
3019 v_result(&ppre[tri[j+2]].px,&ppre[tri[j]].px,p2p0);
3020 v_norm(p0p1,p0);
3021 v_norm(p1p2,p1);
3022 v_norm(p2p0,p2);
3023
3024 sp[0]=v_sprod(p0,p1);
3025 sp[1]=v_sprod(p1,p2);
3026 sp[2]=v_sprod(p2,p0);
3027 for (n=0; n<3; n++) if(sp[n]*sp[n]>MIN_ANGLE_TRI3) return(0);
3028 j+=3;
3029 }
3030 return(1);
3031 }
3032
3033
3034
determineBestCorners(int s,int * cl)3035 int determineBestCorners( int s, int *cl)
3036 {
3037 int i,j;
3038 double v01[3],v02[3],vnorm[3];
3039 double *fi, fi_min=MAX_INTEGER;
3040
3041 if((fi=(double *)malloc((surf[s].nl+1)*sizeof(double) ) )==NULL)
3042 { printf(" ERROR: malloc failure in determineBestCorners()\n"); return(-1); }
3043
3044 /* calculate the angle between two corners based on the end-points */
3045 for(i=0; i<surf[s].nl; i++)
3046 {
3047 if(i==surf[s].nl-1) j=0;
3048 else j=i+1;
3049 if(surf[s].typ[i]=='l')
3050 {
3051 v_result( &point[line[surf[s].l[i]].p1].px,&point[line[surf[s].l[i]].p2].px , v01 );
3052 }
3053 else
3054 {
3055 v_result( &point[lcmb[surf[s].l[i]].p1].px,&point[lcmb[surf[s].l[i]].p2].px , v01 );
3056 }
3057 if(surf[s].typ[j]=='l')
3058 {
3059 v_result( &point[line[surf[s].l[j]].p1].px,&point[line[surf[s].l[j]].p2].px , v02 );
3060 }
3061 else
3062 {
3063 v_result( &point[lcmb[surf[s].l[j]].p1].px,&point[lcmb[surf[s].l[j]].p2].px , v02 );
3064 }
3065
3066 /* determine the smallest angle between two lines */
3067 /*
3068 v_norm( v01, e01 );
3069 v_norm( v02, e02 );
3070 fi[i]=abs(v_sprod( e01, e02 ));
3071 if(fi[i]>fi_max) { fi_max=fi[i]; cl[0]=i; cl[1]=j; }
3072 */
3073
3074 /* determine the smallest cross-product between two lines (small angle and small lines) */
3075 v_prod( v01, v02, vnorm);
3076 fi[i]=abs(v_betrag(vnorm));
3077 if(fi[i]<fi_min) { fi_min=fi[i]; cl[0]=i; cl[1]=j; }
3078
3079 #if TEST
3080 if(surf[s].typ[i]=='l') printf("fi:%lf %s\n", fi[i], line[surf[s].l[i]].name);
3081 else printf("fi:%lf %s\n", fi[i], lcmb[surf[s].l[i]].name);
3082 if(surf[s].typ[j]=='l') printf(" %s\n", line[surf[s].l[j]].name);
3083 else printf(" %s\n", lcmb[surf[s].l[j]].name);
3084 #endif
3085 }
3086
3087 free(fi);
3088 return(1);
3089 }
3090
3091
3092
thread_repSurf(void * vargp)3093 void *thread_repSurf( void *vargp)
3094 {
3095 int j,sur;
3096 int setNr, anz_s;
3097
3098 typedef struct {
3099 int vargp[3];
3100 } Threadargs;
3101 Threadargs *param;
3102
3103 param=(Threadargs *)vargp;
3104 setNr=param->vargp[0];
3105 anz_s=param->vargp[1];
3106 //thrd =param->vargp[2];
3107
3108 while(1)
3109 {
3110 sem_wait(&sem_g);
3111 sur=glob_repsur++;
3112 sem_post(&sem_g);
3113 if(sur>=anz_s) break;
3114 j=set[setNr].surf[sur];
3115 //printf("thrd:%d sur:%d %s\n",thrd, sur, surf[j].name);
3116 repSurf(j,1);
3117 }
3118 return((void *)1);
3119 }
3120
3121
3122
pre_repSurf(int setNr)3123 void pre_repSurf( int setNr)
3124 {
3125 int i, nr, anz_s, nurbsnr;
3126 pthread_t *tid=NULL;
3127 int nlocalThreads, anz_threads;
3128
3129 typedef struct {
3130 int vargp[3];
3131 } Threadargs;
3132 Threadargs *targ=NULL;
3133 int pbuf[4], lbuf[4], sbuf;
3134
3135 delSet(specialset->glur );
3136 set_glur=pre_seta(specialset->glur, "i", 0);
3137 set_blr=pre_seta(specialset->blr, "i", 0);
3138
3139 /* create deleted surfaces for temporary use in surfToNurs() */
3140 for(i=0; i<4; i++)
3141 {
3142 sprintf(buffer,"-pa%d", i+1);
3143 pbuf[i]=pnt( buffer, 0.,0.,0., 0 );
3144 }
3145 for(i=0; i<3; i++)
3146 {
3147 sprintf(buffer,"-l%d", i+1);
3148 lbuf[i]=line_i( buffer, pbuf[i], pbuf[i+1], 0, 1, 1, 0 );
3149 }
3150 sprintf(buffer,"-l%d", i+1);
3151 lbuf[i]=line_i( buffer, pbuf[i], pbuf[0], 0, 1, 1, 0 );
3152 sbuf=surface_i( "-1s", '+', -1, (int)4, "++++", lbuf, "llll");
3153 delPnt( 4, pbuf );
3154 delLine( 4, lbuf );
3155 delSurf( 1, &sbuf );
3156
3157 /* threaded surface evaluation */
3158 anz_s=set[setNr].anz_s;
3159 if(anz->threads>anz_s) { nlocalThreads=anz_s; }
3160 else nlocalThreads=anz->threads;
3161 if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return;}
3162 if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return;}
3163 glob_repsur=0;
3164 anz_threads=anz->threads;
3165 anz->threads=1;
3166 for(i=0; i<nlocalThreads; i++)
3167 {
3168 targ[i].vargp[0]=setNr;
3169 targ[i].vargp[1]=anz_s;
3170 targ[i].vargp[2]=i;
3171 //printf("thread_repSurf trdout:%d\n",i);
3172 //thread_repSurf((void *)&targ[i]);
3173 pthread_create(&tid[i],NULL,thread_repSurf,(void *)&targ[i]);
3174 }
3175 for(i=0; i<nlocalThreads; i++)
3176 {
3177 //printf("thread_repSurf trdin:%d\n",i);
3178 pthread_join(tid[i], NULL);
3179 }
3180 anz->threads=anz_threads;
3181 glob_repsur=0;
3182 free(tid); tid=NULL;
3183 free(targ); targ=NULL;
3184
3185 /* fill the failed surfs with glu */
3186 if(set[set_glur].anz_s>0)
3187 {
3188 set[set_glur].anz_n=0;
3189 for(i=0; i<set[set_glur].anz_s; i++)
3190 {
3191 nr=set[set_glur].surf[i];
3192 if((surf[nr].npgn<=0)&&(shape[surf[nr].sh].type==4))
3193 {
3194 nurbsnr=shape[surf[nr].sh].p[0];
3195 fillNurbsSurf(nurbsnr, nr);
3196 }
3197 }
3198 }
3199 delSet(specialset->glur);
3200 delSet(specialset->blr);
3201
3202 return;
3203 }
3204
3205
thread_evalSurf(void * vargp)3206 void *thread_evalSurf( void *vargp)
3207 {
3208 int j,sur;
3209 int setNr, anz_s, meshflag, returnPtr, renderFlag;
3210 int *mapsurf;
3211
3212 typedef struct {
3213 int vargp[6];
3214 int *mapsurf;
3215 int meshflag;
3216 } Threadargs;
3217 Threadargs *param;
3218
3219 param=(Threadargs *)vargp;
3220 setNr=param->vargp[0];
3221 renderFlag=param->vargp[2];
3222 anz_s=param->vargp[4];
3223 mapsurf=param->mapsurf;
3224 meshflag=param->meshflag;
3225
3226 while(1)
3227 {
3228 sem_wait(&sem_g);
3229 sur=glob_meshsur++;
3230 sem_post(&sem_g);
3231 if(sur>=anz_s) break;
3232 j=set[setNr].surf[sur];
3233 //printf("thread:%d sur:%d %s\n",param->vargp[3], sur, surf[j].name);
3234 returnPtr=meshSurf(anz_s, j, sur, mapsurf, meshflag, renderFlag);
3235
3236 if(returnPtr<0)
3237 {
3238 param->vargp[5]++;
3239 seta(set_nomesh,"s",j);
3240 if(returnPtr==-2) seta(set_glur, "s", j);
3241 }
3242 }
3243 return((void *)1);
3244 }
3245
3246
3247 /**********************************************************************************/
3248 /* */
3249 /* creates temporary-nodes and final elements in all surfaces */
3250 /* */
3251 /**********************************************************************************/
meshSurfs(int setNr,int renderFlag)3252 int meshSurfs( int setNr, int renderFlag)
3253 {
3254 int i,j,n,s;
3255 int noSurfMesh=0, meshflag, anz_s;
3256 int *mapsurf=NULL, *sh_buf=NULL;
3257
3258 typedef struct {
3259 int vargp[6];
3260 int *mapsurf;
3261 int meshflag;
3262 } Threadargs;
3263 Threadargs *targ=NULL;
3264 pthread_t *tid=NULL;
3265 int nlocalThreads;
3266
3267 int *setTmp=NULL, Stmp=-1;
3268 int pbuf[4], lbuf[4], sbuf;
3269
3270 /* copy the amount of surfaces to be meshed, this is necessary because during meshing new surfs */
3271 /* could be created which should not be meshed (substitute surfs for 3- and 5-sided surfs) */
3272 anz_s=set[setNr].anz_s;
3273
3274 /* buffer for substituted surfs */
3275 if ((mapsurf = (int *)realloc((int *)mapsurf, (anz_s+1)*sizeof(int)) ) == NULL )
3276 { printf(" ERROR: realloc failure\n\n"); }
3277 if ((sh_buf = (int *)realloc((int *)sh_buf, (anz_s+1)*sizeof(int)) ) == NULL )
3278 { printf(" ERROR: realloc failure\n\n"); }
3279 if ((setTmp = (int *)realloc((int *)setTmp, (anz_s+1)*sizeof(int)) ) == NULL )
3280 { printf(" ERROR: realloc failure\n\n"); }
3281 for (s=0; s<anz_s; s++) { mapsurf[s]=sh_buf[s]=setTmp[s]=-1; }
3282
3283 for (s=0; s<anz_s; s++)
3284 {
3285 j=set[setNr].surf[s];
3286
3287 /* check if the surface is meshable */
3288 if(surf[j].o==NULL) continue;
3289 if(surf[j].o[0]==0) continue;
3290
3291 if(surf[j].eattr>=0) mapsurf[s]=substituteSurf(j);
3292 else if(surf[j].eattr==-1)
3293 {
3294 /* if shape=BLEND try to generate a shape as a basis for the mesh */
3295 if(surf[j].sh<0)
3296 {
3297 if(surfToShape(j)<0)
3298 {
3299 mapsurf[s]=substituteSurf(j);
3300 continue;
3301 }
3302 else { if(printFlag) printf (" define shape for surf:%s\n", surf[j].name); }
3303 }
3304
3305 /* if shape, generate prelim nurbs */
3306 if(shape[surf[j].sh].type>-1) Stmp= surfToNurs(j);
3307
3308 if(Stmp>-1)
3309 {
3310 sprintf(buffer,"-Stmp%d", j);
3311 delSet(buffer);
3312 setTmp[s]=pre_seta( buffer, "S", nurbs[Stmp].name );
3313 if(setTmp[s]<0)
3314 {
3315 printf(" ERROR: in meshSurf, temporary nurbs could not be added to set %s\n", buffer);
3316 return(-2);
3317 }
3318 completeSet( buffer, "do" );
3319
3320 sh_buf[s]=surf[j].sh;
3321 surf[j].sh=shape_i( nurbs[Stmp].name, 4, Stmp, 0, 0, 0, 0, 0, 0);
3322
3323 if(printFlag) printf (" interior changed to Nurbs: %s\n", nurbs[Stmp].name );
3324 }
3325 }
3326 /* create the uv patch (from mesh_tr3u()) */
3327 //repSurf(j, 0);
3328 //if(mapsurf[s]>-1) printf("surfs to map %d %d \n",s, mapsurf[s]);
3329 }
3330
3331 /* check if bodies will be meshed, if yes also surfaces w/o element assignment have to be meshed */
3332 meshflag=0;
3333 for (i=0; i<set[setNr].anz_b; i++)
3334 {
3335 if(( body[set[setNr].body[i]].etyp==1)||( body[set[setNr].body[i]].etyp==4)) meshflag=1;
3336 }
3337
3338 delSet(specialset->glur );
3339 set_glur=pre_seta(specialset->glur, "i", 0);
3340
3341 /* create deleted surfaces for temporary use in surfToNurs() */
3342 for(i=0; i<4; i++)
3343 {
3344 sprintf(buffer,"-pa%d", i+1);
3345 pbuf[i]=pnt( buffer, 0.,0.,0., 0 );
3346 }
3347 for(i=0; i<3; i++)
3348 {
3349 sprintf(buffer,"-l%d", i+1);
3350 lbuf[i]=line_i( buffer, pbuf[i], pbuf[i+1], 0, 1, 1, 0 );
3351 }
3352 sprintf(buffer,"-l%d", i+1);
3353 lbuf[i]=line_i( buffer, pbuf[i], pbuf[0], 0, 1, 1, 0 );
3354 sbuf=surface_i( "-1s", '+', -1, (int)4, "++++", lbuf, "llll");
3355 delPnt( 4, pbuf );
3356 delLine( 4, lbuf );
3357 delSurf( 1, &sbuf );
3358
3359 /* threaded surface evaluation */
3360 if(anz->threads>anz_s) { nlocalThreads=anz_s; }
3361 else nlocalThreads=anz->threads;
3362 //nlocalThreads=1;
3363 if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
3364 if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
3365 glob_meshsur=0;
3366 for(i=0; i<nlocalThreads; i++)
3367 {
3368 targ[i].vargp[0]=setNr;
3369 targ[i].vargp[2]=renderFlag;
3370 targ[i].vargp[3]=i;
3371 targ[i].vargp[4]=anz_s;
3372 targ[i].vargp[5]=0;
3373 targ[i].mapsurf=mapsurf;
3374 targ[i].meshflag=meshflag;
3375 //printf(" surf thread:%d\n",i);
3376 //thread_evalSurf((void *)&targ[i]);
3377 //noSurfMesh+=targ[i].vargp[5];
3378 pthread_create(&tid[i],NULL,thread_evalSurf,(void *)&targ[i]);
3379 }
3380 for(i=0; i<nlocalThreads; i++)
3381 {
3382 pthread_join(tid[i], NULL);
3383 noSurfMesh+=targ[i].vargp[5];
3384 }
3385 glob_meshsur=0;
3386 free(tid); tid=NULL;
3387 free(targ); targ=NULL;
3388
3389 /* fill the failed surfs with glu */
3390 if(set[set_glur].anz_s>0)
3391 {
3392 set[set_glur].anz_n=0;
3393 for(i=0; i<set[set_glur].anz_s; i++)
3394 {
3395 j=set[set_glur].surf[i];
3396 if((surf[j].npgn<=0)&&(surf[j].sh>-1)&&(shape[surf[j].sh].type==4))
3397 {
3398 n=shape[surf[j].sh].p[0];
3399 fillNurbsSurf(n, j);
3400 }
3401 }
3402 }
3403 delSet(specialset->glur);
3404
3405 /* delete temporary nurbs */
3406 for (s=0; s<anz_s; s++)
3407 {
3408 if(sh_buf[s]>-1)
3409 {
3410 j=set[setNr].surf[s];
3411 surf[j].sh=sh_buf[s];
3412 }
3413 if(setTmp[s]>-1)
3414 {
3415 delNurs( set[setTmp[s]].anz_nurs, set[setTmp[s]].nurs );
3416 delPnt( set[setTmp[s]].anz_p, set[setTmp[s]].pnt );
3417 delSet( set[setTmp[s]].name );
3418 }
3419 }
3420 free(mapsurf);
3421 free(sh_buf);
3422 free(setTmp);
3423
3424 return(noSurfMesh);
3425 }
3426
3427
3428
evalBody(int b_indx,int * srefp)3429 int evalBody( int b_indx, int *srefp )
3430 {
3431 int n, s;
3432 int umax, vmax, wmax;
3433
3434 /* surfs are all balanced, determine umax etc. */
3435 s=0;
3436 if (body[b_indx].o[s]=='+')
3437 {
3438 if ((srefp[s]==0)||(srefp[s]==2))
3439 {
3440 wmax=body[b_indx].div_l[s][0]+1;
3441 vmax=body[b_indx].div_l[s][1]+1;
3442 }
3443 else if ((srefp[s]==1)||(srefp[s]==3))
3444 {
3445 wmax=body[b_indx].div_l[s][1]+1;
3446 vmax=body[b_indx].div_l[s][0]+1;
3447 }
3448 else
3449 {
3450 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3451 exit(-1);
3452 }
3453 }
3454 else
3455 {
3456 if ((srefp[s]==0)||(srefp[s]==2))
3457 {
3458 wmax=body[b_indx].div_l[s][1]+1;
3459 vmax=body[b_indx].div_l[s][0]+1;
3460 }
3461 else if ((srefp[s]==1)||(srefp[s]==3))
3462 {
3463 wmax=body[b_indx].div_l[s][0]+1;
3464 vmax=body[b_indx].div_l[s][1]+1;
3465 }
3466 else
3467 {
3468 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3469 exit(-1);
3470 }
3471 }
3472
3473 /* bestimme die parametrischen Kantenlaengen des bodies, s3 fuer u,w */
3474 s=3;
3475 /* n=srefp[3]; ist gleich der LinienNr die die u-achse beschreibt, wenn die ori. der surf '+' ist */
3476 n=srefp[s]; /* Body-Surf edgenr */
3477 if (body[b_indx].o[s]=='-')
3478 {
3479 if( n==0) n=3;
3480 else if( n==1) n=0;
3481 else if( n==2) n=1;
3482 else if( n==3) n=2;
3483 }
3484 umax=body[b_indx].div_l[s][n]+1;
3485 if(printFlag) printf ("Nr of Nodes in 3D umax:%d vmax:%d wmax:%d\n", umax, vmax, wmax );
3486
3487 body[b_indx].umax=umax;
3488 body[b_indx].vmax=vmax;
3489 body[b_indx].wmax=wmax;
3490 return(1);
3491 }
3492
3493
3494
3495
3496 /**********************************************************************************/
3497 /* Fuellt ein xyz- und nodeNr-feld mit den koordinaten eines Bodies bei der */
3498 /* gegenueber liegende seiten gleiche divisions haben. */
3499 /* Die u-achse laeuft von bcp0 nach bcp4 */
3500 /* Die v-achse laeuft von bcp0 nach bcp1 */
3501 /* Die w-achse laeuft von bcp0 nach bcp3 */
3502 /* */
3503 /* bestimmung der Referenzpunkte der Surfaces: */
3504 /* srefp[0]=cp-index der Bodysurf:0 der mit bcp[0] zussammenfaellt. */
3505 /* srefp[1]=cp-index der Bodysurf:1 der mit bcp[7] zussammenfaellt. */
3506 /* srefp[2]=cp-index der Bodysurf:2 der mit bcp[0] zussammenfaellt. */
3507 /* srefp[3]=cp-index der Bodysurf:3 der mit bcp[0] zussammenfaellt. */
3508 /* srefp[4]=cp-index der Bodysurf:4 der mit bcp[3] zussammenfaellt. */
3509 /* srefp[5]=cp-index der Bodysurf:5 der mit bcp[1] zussammenfaellt. */
3510 /* */
3511 /* */
3512 /* in: */
3513 /* b body -index */
3514 /* srefp surface-reference-points */
3515 /* umax, vmax, wmax Anzahl nodes in den drei richtungen (div+1) */
3516 /* */
3517 /* out: */
3518 /* n_uvw alle nodeNrs im uvw-feld */
3519 /* */
3520 /* */
3521 /**********************************************************************************/
fillBody(int b_indx,int ** pn_uvw)3522 int fillBody( int b_indx, int **pn_uvw)
3523 {
3524 int s,j,n,k,l,m;
3525 int usmax, vsmax, us, vs, u,v,w, nodnr;
3526 double rv, rw, dx,dy,dz, xn,yn,zn;
3527 int *div_l=NULL;
3528 int *n_uv=NULL; /* for edgenodes() */
3529
3530 int umax, vmax, wmax, *n_uvw, *srefp;
3531 double *x, *y, *z;
3532
3533
3534 umax=body[b_indx].umax;
3535 vmax=body[b_indx].vmax;
3536 wmax=body[b_indx].wmax;
3537 srefp=&body[b_indx].s_indx[0];
3538
3539 if( (n_uvw=(int *)malloc((umax)*(vmax)*(wmax)*sizeof(int)) ) == NULL )
3540 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3541 if( (x=(double *)malloc((umax)*(vmax)*(wmax)*sizeof(double)) ) == NULL )
3542 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3543 if( (y=(double *)malloc((umax)*(vmax)*(wmax)*sizeof(double)) ) == NULL )
3544 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3545 if( (z=(double *)malloc((umax)*(vmax)*(wmax)*sizeof(double)) ) == NULL )
3546 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3547
3548 *pn_uvw=n_uvw;
3549
3550 /* allocate memory for embeded nodes */
3551 if((body[b_indx].nod=(int *)realloc((int *)body[b_indx].nod,((umax-2)*(vmax-2)*(wmax-2))*sizeof(int)))==NULL)
3552 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3553
3554 /* einlesen der Nodes der surf (1) in die Node-liste des Bodies */
3555 /* surf1 liegt in der w-v ebene, u=umax-1 */
3556 s=1;
3557 u=umax-1;
3558 j=body[b_indx].s[s];
3559
3560 if( (n_uv=(int *)realloc((int *)n_uv, (umax)*(vmax)*(wmax)*sizeof(int)) ) == NULL )
3561 { printf(" ERROR: realloc failure in fillBody(), body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3562 if( (div_l=(int *)realloc((int *)div_l, (surf[j].nl+1)*sizeof(int)) ) == NULL )
3563 { printf(" ERROR: realloc failure in fillBody(), body:%s can not be meshed\n\n", body[b_indx].name); return(-1); }
3564
3565 #if TEST
3566 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
3567 #endif
3568
3569 if (surf[j].nl!=MAX_EDGES_PER_SURF)
3570 {
3571 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
3572 return(-1);
3573 }
3574 for (n=0; n<surf[j].nl; n++)
3575 {
3576 k=surf[j].l[n];
3577 div_l[n]=0;
3578 if( surf[j].typ[n]=='c' )
3579 {
3580 for( l=0; l<lcmb[k].nl; l++ )
3581 {
3582 m=lcmb[k].l[l];
3583 div_l[n]+=line[m].div;
3584 }
3585 }
3586 else
3587 div_l[n]+=line[k].div;
3588 }
3589 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
3590 {
3591 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
3592 div_l[0], div_l[1], div_l[2], div_l[3] );
3593 return(-1);
3594 }
3595 vsmax=div_l[3]+1;
3596 usmax=div_l[0]+1;
3597 edgeNodes( vsmax, usmax, j, n_uv );
3598
3599 /* belege die Randknoten */
3600 /* abhaengig von der orientierung und dem referenzpunkt der surface */
3601 for (us=0; us<usmax; us++)
3602 {
3603 for (vs=0; vs<vsmax; vs++)
3604 {
3605 nodnr=n_uv[us*vsmax +vs];
3606 if (nodnr>-1)
3607 {
3608 if (srefp[s]==0) /* edge der surf am refpunkt */
3609 {
3610 if (body[b_indx].o[s]=='+')
3611 {
3612 w=usmax-us-1;
3613 v=vs;
3614 }
3615 else
3616 {
3617 w=vsmax-vs-1;
3618 v=us;
3619 }
3620 }
3621 else if (srefp[s]==1) /* edge der surf am refpunkt */
3622 {
3623 if (body[b_indx].o[s]=='+')
3624 {
3625 w=vsmax-vs-1;
3626 v=usmax-us-1;
3627 }
3628 else
3629 {
3630 w=us;
3631 v=vs;
3632 }
3633 }
3634 else if (srefp[s]==2) /* edge der surf am refpunkt */
3635 {
3636 if (body[b_indx].o[s]=='+')
3637 {
3638 /*
3639 w=vsmax-vs-1;
3640 v=us;
3641 */
3642 v=vsmax-vs-1;
3643 w=us;
3644 }
3645 else
3646 {
3647 /*
3648 w=usmax-us-1;
3649 v=vs;
3650 */
3651 v=usmax-us-1;
3652 w=vs;
3653 }
3654 }
3655 else if (srefp[s]==3) /* edge der surf am refpunkt */
3656 {
3657 if (body[b_indx].o[s]=='+')
3658 {
3659 w=vs;
3660 v=us;
3661 }
3662 else
3663 {
3664 w=usmax-us-1;
3665 v=vsmax-vs-1;
3666 }
3667 }
3668 else
3669 {
3670 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3671 exit(-1);
3672 }
3673 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
3674 sem_wait(&sem_n);
3675 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
3676 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
3677 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
3678 sem_post(&sem_n);
3679 #if TEST
3680 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
3681 sprintf( buffer, "%d ", nodnr);
3682 sprintf( namebuf, "bs%d ", s);
3683 sem_wait(&sem_g);
3684 pre_seta( namebuf, "n", buffer);
3685 sem_post(&sem_g);
3686 #endif
3687
3688 }
3689 }
3690 }
3691 /* auffuellen der surface mit nodes */
3692 k=0;
3693 for (us=1; us<div_l[0]; us++)
3694 {
3695 for (vs=1; vs<div_l[3]; vs++)
3696 {
3697 nodnr=surf[j].nod[k];
3698 if (srefp[s]==0) /* edge der surf am refpunkt */
3699 {
3700 if (body[b_indx].o[s]=='+')
3701 {
3702 w=usmax-us-1;
3703 v=vs;
3704 }
3705 else
3706 {
3707 w=vsmax-vs-1;
3708 v=us;
3709 }
3710 }
3711 else if (srefp[s]==1) /* edge der surf am refpunkt */
3712 {
3713 if (body[b_indx].o[s]=='+')
3714 {
3715 w=vsmax-vs-1;
3716 v=usmax-us-1;
3717 }
3718 else
3719 {
3720 w=us;
3721 v=vs;
3722 }
3723 }
3724 else if (srefp[s]==2) /* edge der surf am refpunkt */
3725 {
3726 if (body[b_indx].o[s]=='+')
3727 {
3728 /*
3729 w=vsmax-vs-1;
3730 v=us;
3731 */
3732 v=vsmax-vs-1;
3733 w=us;
3734 }
3735 else
3736 {
3737 /*
3738 w=usmax-us-1;
3739 v=vs;
3740 */
3741 v=usmax-us-1;
3742 w=vs;
3743 }
3744 }
3745 else if (srefp[s]==3) /* edge der surf am refpunkt */
3746 {
3747 if (body[b_indx].o[s]=='+')
3748 {
3749 w=vs;
3750 v=us;
3751 }
3752 else
3753 {
3754 w=usmax-us-1;
3755 v=vsmax-vs-1;
3756 }
3757 }
3758 else
3759 {
3760 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3761 exit(-1);
3762 }
3763 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
3764 sem_wait(&sem_n);
3765 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
3766 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
3767 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
3768 sem_post(&sem_n);
3769 #if TEST
3770 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
3771 sprintf( buffer, "%d ", nodnr);
3772 sprintf( namebuf, "bs%d ", s);
3773 sem_wait(&sem_g);
3774 pre_seta( namebuf, "n", buffer);
3775 sem_post(&sem_g);
3776 #endif
3777
3778 k++;
3779 }
3780 }
3781
3782
3783 /* surf4 liegt in der u-v ebene, w=wmax-1 */
3784 s=4;
3785 w=wmax-1;
3786 j=body[b_indx].s[s];
3787
3788 #if TEST
3789 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
3790 #endif
3791
3792 if (surf[j].nl!=MAX_EDGES_PER_SURF)
3793 {
3794 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
3795 return(-1);
3796 }
3797 for (n=0; n<surf[j].nl; n++)
3798 {
3799 k=surf[j].l[n];
3800 div_l[n]=0;
3801 if( surf[j].typ[n]=='c' )
3802 {
3803 for( l=0; l<lcmb[k].nl; l++ )
3804 {
3805 m=lcmb[k].l[l];
3806 div_l[n]+=line[m].div;
3807 }
3808 }
3809 else
3810 div_l[n]+=line[k].div;
3811 }
3812 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
3813 {
3814 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
3815 div_l[0], div_l[1], div_l[2], div_l[3] );
3816 return(-1);
3817 }
3818 vsmax=div_l[3]+1;
3819 usmax=div_l[0]+1;
3820 edgeNodes( vsmax, usmax, j, n_uv );
3821
3822 /* belege die Randknoten */
3823 /* abhaengig von der orientierung und dem referenzpunkt der surface */
3824 for (us=0; us<usmax; us++)
3825 {
3826 for (vs=0; vs<vsmax; vs++)
3827 {
3828 nodnr=n_uv[us*vsmax +vs];
3829 if (nodnr>-1)
3830 {
3831 if (srefp[s]==0) /* edge der surf am refpunkt */
3832 {
3833 if (body[b_indx].o[s]=='+')
3834 {
3835 v=vs;
3836 u=us;
3837 }
3838 else
3839 {
3840 v=us;
3841 u=vs;
3842 }
3843 }
3844 else if (srefp[s]==1) /* edge der surf am refpunkt */
3845 {
3846 if (body[b_indx].o[s]=='+')
3847 {
3848 u=vs;
3849 v=usmax-us-1;
3850 }
3851 else
3852 {
3853 u=usmax-us-1;
3854 v=vs;
3855 }
3856 }
3857 else if (srefp[s]==2) /* edge der surf am refpunkt */
3858 {
3859 if (body[b_indx].o[s]=='+')
3860 {
3861 v=vsmax-vs-1;
3862 u=usmax-us-1;
3863 }
3864 else
3865 {
3866 v=usmax-us-1;
3867 u=vsmax-vs-1;
3868 }
3869 }
3870 else if (srefp[s]==3) /* edge der surf am refpunkt */
3871 {
3872 if (body[b_indx].o[s]=='+')
3873 {
3874 u=vsmax-vs-1;
3875 v=us;
3876 }
3877 else
3878 {
3879 u=us;
3880 v=vsmax-vs-1;
3881 }
3882 }
3883 else
3884 {
3885 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3886 exit(-1);
3887 }
3888 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
3889 sem_wait(&sem_n);
3890 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
3891 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
3892 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
3893 sem_post(&sem_n);
3894 #if TEST
3895 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
3896 sprintf( buffer, "%d ", nodnr);
3897 sprintf( namebuf, "bs%d ", s);
3898 sem_wait(&sem_g);
3899 pre_seta( namebuf, "n", buffer);
3900 sem_post(&sem_g);
3901 #endif
3902
3903 }
3904 }
3905 }
3906 /* auff�llen der surface mit nodes */
3907 k=0;
3908 for (us=1; us<div_l[0]; us++)
3909 {
3910 for (vs=1; vs<div_l[3]; vs++)
3911 {
3912 nodnr=surf[j].nod[k];
3913 if (srefp[s]==0) /* edge der surf am refpunkt */
3914 {
3915 if (body[b_indx].o[s]=='+')
3916 {
3917 v=vs;
3918 u=us;
3919 }
3920 else
3921 {
3922 v=us;
3923 u=vs;
3924 }
3925 }
3926 else if (srefp[s]==1) /* edge der surf am refpunkt */
3927 {
3928 if (body[b_indx].o[s]=='+')
3929 {
3930 u=vs;
3931 v=usmax-us-1;
3932 }
3933 else
3934 {
3935 u=usmax-us-1;
3936 v=vs;
3937 }
3938 }
3939 else if (srefp[s]==2) /* edge der surf am refpunkt */
3940 {
3941 if (body[b_indx].o[s]=='+')
3942 {
3943 v=vsmax-vs-1;
3944 u=usmax-us-1;
3945 }
3946 else
3947 {
3948 v=usmax-us-1;
3949 u=vsmax-vs-1;
3950 }
3951 }
3952 else if (srefp[s]==3) /* edge der surf am refpunkt */
3953 {
3954 if (body[b_indx].o[s]=='+')
3955 {
3956 u=vsmax-vs-1;
3957 v=us;
3958 }
3959 else
3960 {
3961 u=us;
3962 v=vsmax-vs-1;
3963 }
3964 }
3965 else
3966 {
3967 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
3968 exit(-1);
3969 }
3970 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
3971 sem_wait(&sem_n);
3972 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
3973 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
3974 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
3975 sem_post(&sem_n);
3976 #if TEST
3977 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
3978 sprintf( buffer, "%d ", nodnr);
3979 sprintf( namebuf, "bs%d ", s);
3980 sem_wait(&sem_g);
3981 pre_seta( namebuf, "n", buffer);
3982 sem_post(&sem_g);
3983 #endif
3984
3985 k++;
3986 }
3987 }
3988
3989
3990
3991 /* einlesen der Nodes der surf (2) in die Node-liste des Bodies */
3992 /* surf2 liegt in der u-v ebene, w=0 */
3993 s=2;
3994 w=0;
3995 j=body[b_indx].s[s];
3996
3997 #if TEST
3998 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
3999 #endif
4000
4001 if (surf[j].nl!=MAX_EDGES_PER_SURF)
4002 {
4003 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
4004 return(-1);
4005 }
4006 for (n=0; n<surf[j].nl; n++)
4007 {
4008 k=surf[j].l[n];
4009 div_l[n]=0;
4010 if( surf[j].typ[n]=='c' )
4011 {
4012 for( l=0; l<lcmb[k].nl; l++ )
4013 {
4014 m=lcmb[k].l[l];
4015 div_l[n]+=line[m].div;
4016 }
4017 }
4018 else
4019 div_l[n]+=line[k].div;
4020 }
4021 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
4022 {
4023 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
4024 div_l[0], div_l[1], div_l[2], div_l[3] );
4025 return(-1);
4026 }
4027 vsmax=div_l[3]+1;
4028 usmax=div_l[0]+1;
4029 edgeNodes( vsmax, usmax, j, n_uv );
4030
4031 /* belege die Randknoten */
4032 /* abhaengig von der orientierung und dem referenzpunkt der surface */
4033 for (us=0; us<usmax; us++)
4034 {
4035 for (vs=0; vs<vsmax; vs++)
4036 {
4037 nodnr=n_uv[us*vsmax +vs];
4038 if (nodnr>-1)
4039 {
4040 if (srefp[s]==0) /* edge der surf am refpunkt */
4041 {
4042 if (body[b_indx].o[s]=='+')
4043 {
4044 u=vs;
4045 v=us;
4046 }
4047 else
4048 {
4049 u=us;
4050 v=vs;
4051 }
4052 }
4053 else if (srefp[s]==1) /* edge der surf am refpunkt */
4054 {
4055 if (body[b_indx].o[s]=='+')
4056 {
4057 u=usmax-us-1;
4058 v=vs;
4059 }
4060 else
4061 {
4062 u=vs;
4063 v=usmax-1-us;
4064 }
4065 }
4066 else if (srefp[s]==2) /* edge der surf am refpunkt */
4067 {
4068 if (body[b_indx].o[s]=='+')
4069 {
4070 u=vsmax-1-vs;
4071 v=usmax-1-us;
4072 }
4073 else
4074 {
4075 u=usmax-1-us;
4076 v=vsmax-vs-1;
4077 }
4078 }
4079 else if (srefp[s]==3) /* edge der surf am refpunkt */
4080 {
4081 if (body[b_indx].o[s]=='+')
4082 {
4083 u=us;
4084 v=vsmax-1-vs;
4085 }
4086 else
4087 {
4088 u=vsmax-vs-1;
4089 v=us;
4090 }
4091 }
4092 else
4093 {
4094 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4095 exit(-1);
4096 }
4097 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4098 sem_wait(&sem_n);
4099 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4100 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4101 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4102 sem_post(&sem_n);
4103 #if TEST
4104 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4105 sprintf( buffer, "%d ", nodnr);
4106 sprintf( namebuf, "bs%d ", s);
4107 sem_wait(&sem_g);
4108 pre_seta( namebuf, "n", buffer);
4109 sem_post(&sem_g);
4110 #endif
4111
4112 }
4113 }
4114 }
4115 /* auffuellen der surface mit nodes */
4116 k=0;
4117 for (us=1; us<div_l[0]; us++)
4118 {
4119 for (vs=1; vs<div_l[3]; vs++)
4120 {
4121 nodnr=surf[j].nod[k];
4122 if (srefp[s]==0) /* edge der surf am refpunkt */
4123 {
4124 if (body[b_indx].o[s]=='+')
4125 {
4126 u=vs;
4127 v=us;
4128 }
4129 else
4130 {
4131 u=us;
4132 v=vs;
4133 }
4134 }
4135 else if (srefp[s]==1) /* edge der surf am refpunkt */
4136 {
4137 if (body[b_indx].o[s]=='+')
4138 {
4139 u=usmax-us-1;
4140 v=vs;
4141 }
4142 else
4143 {
4144 u=vs;
4145 v=usmax-1-us;
4146 }
4147 }
4148 else if (srefp[s]==2) /* edge der surf am refpunkt */
4149 {
4150 if (body[b_indx].o[s]=='+')
4151 {
4152 u=vsmax-1-vs;
4153 v=usmax-1-us;
4154 }
4155 else
4156 {
4157 u=usmax-1-us;
4158 v=vsmax-vs-1;
4159 }
4160 }
4161 else if (srefp[s]==3) /* edge der surf am refpunkt */
4162 {
4163 if (body[b_indx].o[s]=='+')
4164 {
4165 u=us;
4166 v=vsmax-1-vs;
4167 }
4168 else
4169 {
4170 u=vsmax-vs-1;
4171 v=us;
4172 }
4173 }
4174 else
4175 {
4176 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4177 exit(-1);
4178 }
4179 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4180 sem_wait(&sem_n);
4181 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4182 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4183 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4184 sem_post(&sem_n);
4185 #if TEST
4186 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4187 sprintf( buffer, "%d ", nodnr);
4188 sprintf( namebuf, "bs%d ", s);
4189 sem_wait(&sem_g);
4190 pre_seta( namebuf, "n", buffer);
4191 sem_post(&sem_g);
4192 #endif
4193
4194 k++;
4195 }
4196 }
4197
4198
4199
4200 /* einlesen der Nodes der Mastersurf (0) in die Node-liste des Bodies */
4201 /* surf0 liegt in der w-v ebene, u=0 */
4202 s=0;
4203 u=0;
4204 j=body[b_indx].s[s];
4205
4206 #if TEST
4207 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
4208 #endif
4209
4210 if (surf[j].nl!=MAX_EDGES_PER_SURF)
4211 {
4212 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
4213 return(-1);
4214 }
4215 for (n=0; n<surf[j].nl; n++)
4216 {
4217 k=surf[j].l[n];
4218 div_l[n]=0;
4219 if( surf[j].typ[n]=='c' )
4220 {
4221 for( l=0; l<lcmb[k].nl; l++ )
4222 {
4223 m=lcmb[k].l[l];
4224 div_l[n]+=line[m].div;
4225 }
4226 }
4227 else
4228 div_l[n]+=line[k].div;
4229 }
4230 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
4231 {
4232 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
4233 div_l[0], div_l[1], div_l[2], div_l[3] );
4234 return(-1);
4235 }
4236 vsmax=div_l[3]+1;
4237 usmax=div_l[0]+1;
4238 edgeNodes( vsmax, usmax, j, n_uv );
4239
4240 /* belege die Randknoten */
4241 /* abhaengig von der orientierung und dem referenzpunkt der surface */
4242 for (us=0; us<usmax; us++)
4243 {
4244 for (vs=0; vs<vsmax; vs++)
4245 {
4246 nodnr=n_uv[us*vsmax +vs];
4247 if (nodnr>-1)
4248 {
4249 if (srefp[s]==0) /* edge der surf am refpunkt */
4250 {
4251 if (body[b_indx].o[s]=='+')
4252 {
4253 v=vs;
4254 w=us;
4255 }
4256 else
4257 {
4258 v=us;
4259 w=vs;
4260 }
4261 }
4262 else if (srefp[s]==1) /* edge der surf am refpunkt */
4263 {
4264 if (body[b_indx].o[s]=='+')
4265 {
4266 w=vs;
4267 v=usmax-us-1;
4268 }
4269 else
4270 {
4271 w=usmax-us-1;
4272 v=vs;
4273 }
4274 }
4275 else if (srefp[s]==2) /* edge der surf am refpunkt */
4276 {
4277 if (body[b_indx].o[s]=='+')
4278 {
4279 v=vsmax-vs-1;
4280 w=usmax-us-1;
4281 }
4282 else
4283 {
4284 v=usmax-us-1;
4285 w=vsmax-vs-1;
4286 }
4287 }
4288 else if (srefp[s]==3) /* edge der surf am refpunkt */
4289 {
4290 if (body[b_indx].o[s]=='+')
4291 {
4292 w=vsmax-vs-1;
4293 v=us;
4294 }
4295 else
4296 {
4297 w=us;
4298 v=vsmax-vs-1;
4299 }
4300 }
4301 else
4302 {
4303 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4304 exit(-1);
4305 }
4306 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4307 sem_wait(&sem_n);
4308 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4309 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4310 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4311 sem_post(&sem_n);
4312 #if TEST
4313 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4314 sprintf( buffer, "%d ", nodnr);
4315 sprintf( namebuf, "bs%d ", s);
4316 sem_wait(&sem_g);
4317 pre_seta( namebuf, "n", buffer);
4318 sem_post(&sem_g);
4319 #endif
4320
4321 }
4322 }
4323 }
4324 /* auff�llen der surface mit nodes */
4325 k=0;
4326 for (us=1; us<div_l[0]; us++)
4327 {
4328 for (vs=1; vs<div_l[3]; vs++)
4329 {
4330 nodnr=surf[j].nod[k];
4331 if (srefp[s]==0) /* edge der surf am refpunkt */
4332 {
4333 if (body[b_indx].o[s]=='+')
4334 {
4335 v=vs;
4336 w=us;
4337 }
4338 else
4339 {
4340 v=us;
4341 w=vs;
4342 }
4343 }
4344 else if (srefp[s]==1) /* edge der surf am refpunkt */
4345 {
4346 if (body[b_indx].o[s]=='+')
4347 {
4348 w=vs;
4349 v=usmax-us-1;
4350 }
4351 else
4352 {
4353 w=usmax-us-1;
4354 v=vs;
4355 }
4356 }
4357 else if (srefp[s]==2) /* edge der surf am refpunkt */
4358 {
4359 if (body[b_indx].o[s]=='+')
4360 {
4361 v=vsmax-vs-1;
4362 w=usmax-us-1;
4363 }
4364 else
4365 {
4366 v=usmax-us-1;
4367 w=vsmax-vs-1;
4368 }
4369 }
4370 else if (srefp[s]==3) /* edge der surf am refpunkt */
4371 {
4372 if (body[b_indx].o[s]=='+')
4373 {
4374 w=vsmax-vs-1;
4375 v=us;
4376 }
4377 else
4378 {
4379 w=us;
4380 v=vsmax-vs-1;
4381 }
4382 }
4383 else
4384 {
4385 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4386 exit(-1);
4387 }
4388 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4389 sem_wait(&sem_n);
4390 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4391 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4392 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4393 sem_post(&sem_n);
4394 #if TEST
4395 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4396 sprintf( buffer, "%d ", nodnr);
4397 sprintf( namebuf, "bs%d ", s);
4398 sem_wait(&sem_g);
4399 pre_seta( namebuf, "n", buffer);
4400 sem_post(&sem_g);
4401 #endif
4402
4403 k++;
4404 }
4405 }
4406
4407
4408 /* surf3 liegt in der u-w ebene, v=0 */
4409 s=3;
4410 v=0;
4411 j=body[b_indx].s[s];
4412
4413 #if TEST
4414 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
4415 #endif
4416
4417 if (surf[j].nl!=MAX_EDGES_PER_SURF)
4418 {
4419 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
4420 return(-1);
4421 }
4422 for (n=0; n<surf[j].nl; n++)
4423 {
4424 k=surf[j].l[n];
4425 div_l[n]=0;
4426 if( surf[j].typ[n]=='c' )
4427 {
4428 for( l=0; l<lcmb[k].nl; l++ )
4429 {
4430 m=lcmb[k].l[l];
4431 div_l[n]+=line[m].div;
4432 }
4433 }
4434 else
4435 div_l[n]+=line[k].div;
4436 }
4437 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
4438 {
4439 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
4440 div_l[0], div_l[1], div_l[2], div_l[3] );
4441 return(-1);
4442 }
4443 vsmax=div_l[3]+1;
4444 usmax=div_l[0]+1;
4445 edgeNodes( vsmax, usmax, j, n_uv );
4446
4447 /* belege die Randknoten */
4448 /* abhaengig von der orientierung und dem referenzpunkt der surface */
4449 for (us=0; us<usmax; us++)
4450 {
4451 for (vs=0; vs<vsmax; vs++)
4452 {
4453 nodnr=n_uv[us*vsmax +vs];
4454 if (nodnr>-1)
4455 {
4456 if (srefp[s]==0) /* edge der surf am refpunkt */
4457 {
4458 if (body[b_indx].o[s]=='+')
4459 {
4460 w=vs;
4461 u=us;
4462 }
4463 else
4464 {
4465 w=us;
4466 u=vs;
4467 }
4468 }
4469 else if (srefp[s]==1) /* edge der surf am refpunkt */
4470 {
4471 if (body[b_indx].o[s]=='+')
4472 {
4473 u=vs;
4474 w=usmax-us-1;
4475 }
4476 else
4477 {
4478 u=usmax-us-1;
4479 w=vs;
4480 }
4481 }
4482 else if (srefp[s]==2) /* edge der surf am refpunkt */
4483 {
4484 if (body[b_indx].o[s]=='+')
4485 {
4486 w=vsmax-vs-1;
4487 u=usmax-us-1;
4488 }
4489 else
4490 {
4491 w=usmax-us-1;
4492 u=vsmax-vs-1;
4493 }
4494 }
4495 else if (srefp[s]==3) /* edge der surf am refpunkt */
4496 {
4497 if (body[b_indx].o[s]=='+')
4498 {
4499 u=vsmax-vs-1;
4500 w=us;
4501 }
4502 else
4503 {
4504 u=us;
4505 w=vsmax-vs-1;
4506 }
4507 }
4508 else
4509 {
4510 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4511 exit(-1);
4512 }
4513 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4514 sem_wait(&sem_n);
4515 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4516 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4517 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4518 sem_post(&sem_n);
4519 #if TEST
4520 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4521 sprintf( buffer, "%d ", nodnr);
4522 sprintf( namebuf, "bs%d ", s);
4523 sem_wait(&sem_g);
4524 pre_seta( namebuf, "n", buffer);
4525 sem_post(&sem_g);
4526 #endif
4527
4528 }
4529 }
4530 }
4531 /* auff�llen der surface mit nodes */
4532 k=0;
4533 for (us=1; us<div_l[0]; us++)
4534 {
4535 for (vs=1; vs<div_l[3]; vs++)
4536 {
4537 nodnr=surf[j].nod[k];
4538 if (srefp[s]==0) /* edge der surf am refpunkt */
4539 {
4540 if (body[b_indx].o[s]=='+')
4541 {
4542 w=vs;
4543 u=us;
4544 }
4545 else
4546 {
4547 w=us;
4548 u=vs;
4549 }
4550 }
4551 else if (srefp[s]==1) /* edge der surf am refpunkt */
4552 {
4553 if (body[b_indx].o[s]=='+')
4554 {
4555 u=vs;
4556 w=usmax-us-1;
4557 }
4558 else
4559 {
4560 u=usmax-us-1;
4561 w=vs;
4562 }
4563 }
4564 else if (srefp[s]==2) /* edge der surf am refpunkt */
4565 {
4566 if (body[b_indx].o[s]=='+')
4567 {
4568 w=vsmax-vs-1;
4569 u=usmax-us-1;
4570 }
4571 else
4572 {
4573 w=usmax-us-1;
4574 u=vsmax-vs-1;
4575 }
4576 }
4577 else if (srefp[s]==3) /* edge der surf am refpunkt */
4578 {
4579 if (body[b_indx].o[s]=='+')
4580 {
4581 u=vsmax-vs-1;
4582 w=us;
4583 }
4584 else
4585 {
4586 u=us;
4587 w=vsmax-vs-1;
4588 }
4589 }
4590 else
4591 {
4592 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4593 exit(-1);
4594 }
4595 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4596 sem_wait(&sem_n);
4597 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4598 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4599 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4600 sem_post(&sem_n);
4601 #if TEST
4602 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4603 sprintf( buffer, "%d ", nodnr);
4604 sprintf( namebuf, "bs%d ", s);
4605 sem_wait(&sem_g);
4606 pre_seta( namebuf, "n", buffer);
4607 if(sem_post(&sem_g)) printf("Error in:sem_wait\n");
4608 #endif
4609
4610 k++;
4611 }
4612 }
4613
4614 /* surf5 liegt in der w-u ebene, v=vmax-1 */
4615 s=5;
4616 v=vmax-1;
4617 j=body[b_indx].s[s];
4618
4619 #if TEST
4620 fprintf (handle, "\nsur:%d %s\n", s, surf[j].name);
4621 #endif
4622
4623 if (surf[j].nl!=MAX_EDGES_PER_SURF)
4624 {
4625 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
4626 return(-1);
4627 }
4628 for (n=0; n<surf[j].nl; n++)
4629 {
4630 k=surf[j].l[n];
4631 div_l[n]=0;
4632 if( surf[j].typ[n]=='c' )
4633 {
4634 for( l=0; l<lcmb[k].nl; l++ )
4635 {
4636 m=lcmb[k].l[l];
4637 div_l[n]+=line[m].div;
4638 }
4639 }
4640 else
4641 div_l[n]+=line[k].div;
4642 }
4643 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3]))
4644 {
4645 printf(" ERROR: Surf:%s has unbalanced edges: %d %d %d %d\n", surf[j].name,
4646 div_l[0], div_l[1], div_l[2], div_l[3] );
4647 return(-1);
4648 }
4649 vsmax=div_l[3]+1;
4650 usmax=div_l[0]+1;
4651 edgeNodes( vsmax, usmax, j, n_uv );
4652
4653 /* belege die Randknoten */
4654 /* abhaengig von der orientierung und dem referenzpunkt der surface */
4655 for (us=0; us<usmax; us++)
4656 {
4657 for (vs=0; vs<vsmax; vs++)
4658 {
4659 nodnr=n_uv[us*vsmax +vs];
4660 if (nodnr>-1)
4661 {
4662 if (srefp[s]==0) /* edge der surf am refpunkt */
4663 {
4664 if (body[b_indx].o[s]=='+')
4665 {
4666 u=vs;
4667 w=us;
4668 }
4669 else
4670 {
4671 u=us;
4672 w=vs;
4673 }
4674 }
4675 else if (srefp[s]==1) /* edge der surf am refpunkt */
4676 {
4677 if (body[b_indx].o[s]=='+')
4678 {
4679 w=vs;
4680 u=usmax-us-1;
4681 }
4682 else
4683 {
4684 w=usmax-us-1;
4685 u=vs;
4686 }
4687 }
4688 else if (srefp[s]==2) /* edge der surf am refpunkt */
4689 {
4690 if (body[b_indx].o[s]=='+')
4691 {
4692 u=vsmax-vs-1;
4693 w=usmax-us-1;
4694 }
4695 else
4696 {
4697 u=usmax-us-1;
4698 w=vsmax-vs-1;
4699 }
4700 }
4701 else if (srefp[s]==3) /* edge der surf am refpunkt */
4702 {
4703 if (body[b_indx].o[s]=='+')
4704 {
4705 w=vsmax-vs-1;
4706 u=us;
4707 }
4708 else
4709 {
4710 w=us;
4711 u=vsmax-vs-1;
4712 }
4713 }
4714 else
4715 {
4716 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4717 exit(-1);
4718 }
4719 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4720 sem_wait(&sem_n);
4721 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4722 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4723 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4724 sem_post(&sem_n);
4725 #if TEST
4726 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4727 sprintf( buffer, "%d ", nodnr);
4728 sprintf( namebuf, "bs%d ", s);
4729 sem_wait(&sem_g);
4730 pre_seta( namebuf, "n", buffer);
4731 if(sem_post(&sem_g)) printf("Error in:sem_wait\n");
4732 #endif
4733
4734 }
4735 }
4736 }
4737 /* auff�llen der surface mit nodes */
4738 k=0;
4739 for (us=1; us<div_l[0]; us++)
4740 {
4741 for (vs=1; vs<div_l[3]; vs++)
4742 {
4743 nodnr=surf[j].nod[k];
4744 if (srefp[s]==0) /* edge der surf am refpunkt */
4745 {
4746 if (body[b_indx].o[s]=='+')
4747 {
4748 u=vs;
4749 w=us;
4750 }
4751 else
4752 {
4753 u=us;
4754 w=vs;
4755 }
4756 }
4757 else if (srefp[s]==1) /* edge der surf am refpunkt */
4758 {
4759 if (body[b_indx].o[s]=='+')
4760 {
4761 w=vs;
4762 u=usmax-us-1;
4763 }
4764 else
4765 {
4766 w=usmax-us-1;
4767 u=vs;
4768 }
4769 }
4770 else if (srefp[s]==2) /* edge der surf am refpunkt */
4771 {
4772 if (body[b_indx].o[s]=='+')
4773 {
4774 u=vsmax-vs-1;
4775 w=usmax-us-1;
4776 }
4777 else
4778 {
4779 u=usmax-us-1;
4780 w=vsmax-vs-1;
4781 }
4782 }
4783 else if (srefp[s]==3) /* edge der surf am refpunkt */
4784 {
4785 if (body[b_indx].o[s]=='+')
4786 {
4787 w=vsmax-vs-1;
4788 u=us;
4789 }
4790 else
4791 {
4792 w=us;
4793 u=vsmax-vs-1;
4794 }
4795 }
4796 else
4797 {
4798 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
4799 exit(-1);
4800 }
4801 n_uvw[u*vmax*wmax +v*wmax +w]=nodnr;
4802 sem_wait(&sem_n);
4803 x[u*vmax*wmax +v*wmax +w]=npre[nodnr].nx;
4804 y[u*vmax*wmax +v*wmax +w]=npre[nodnr].ny;
4805 z[u*vmax*wmax +v*wmax +w]=npre[nodnr].nz;
4806 sem_post(&sem_n);
4807 #if TEST
4808 fprintf (handle, "n:%d %d %d %d\n", nodnr, u,v,w);
4809 sprintf( buffer, "%d ", nodnr);
4810 sprintf( namebuf, "bs%d ", s);
4811 sem_wait(&sem_g);
4812 pre_seta( namebuf, "n", buffer);
4813 if(sem_post(&sem_g)) printf("Error in:sem_wait\n");
4814 #endif
4815
4816 k++;
4817 }
4818 }
4819
4820 /* korrigieren der nodeposition der eingebetteten nodes fuer den kollabierten Body */
4821 s=1;
4822 u=umax-1;
4823 j=body[b_indx].s[s];
4824 /* kollabierte seite feststellen, welcher seitenabstand ist 0? */
4825 dx= x[u*vmax*wmax +0*wmax +0]-x[u*vmax*wmax +(vmax-1)*wmax +0];
4826 dy= y[u*vmax*wmax +0*wmax +0]-y[u*vmax*wmax +(vmax-1)*wmax +0];
4827 dz= z[u*vmax*wmax +0*wmax +0]-z[u*vmax*wmax +(vmax-1)*wmax +0];
4828 rv =dx*dx + dy*dy + dz*dz;
4829 dx= x[u*vmax*wmax +0*wmax +0]-x[u*vmax*wmax +0*wmax +(wmax-1)];
4830 dy= y[u*vmax*wmax +0*wmax +0]-y[u*vmax*wmax +0*wmax +(wmax-1)];
4831 dz= z[u*vmax*wmax +0*wmax +0]-z[u*vmax*wmax +0*wmax +(wmax-1)];
4832 rw =dx*dx + dy*dy + dz*dz;
4833 #if TEST
4834 printf("rv=%lf (if 0 colapsed) rw=%lf \n",rv,rw);
4835 #endif
4836 if (rv==0.)
4837 {
4838 for (v=1; v<vmax-1; v++)
4839 {
4840 for (w=1; w<wmax-1; w++)
4841 {
4842 x[u*vmax*wmax +v*wmax +w]=x[u*vmax*wmax +0*wmax +w];
4843 y[u*vmax*wmax +v*wmax +w]=y[u*vmax*wmax +0*wmax +w];
4844 z[u*vmax*wmax +v*wmax +w]=z[u*vmax*wmax +0*wmax +w];
4845 }
4846 }
4847 }
4848 if (rw==0.)
4849 {
4850 for (v=1; v<vmax-1; v++)
4851 {
4852 for (w=1; w<wmax-1; w++)
4853 {
4854 x[u*vmax*wmax +v*wmax +w]=x[u*vmax*wmax +v*wmax +0];
4855 y[u*vmax*wmax +v*wmax +w]=y[u*vmax*wmax +v*wmax +0];
4856 z[u*vmax*wmax +v*wmax +w]=z[u*vmax*wmax +v*wmax +0];
4857 }
4858 }
4859 }
4860
4861 /* auffuellen des bodies mit nodes */
4862 k=0;
4863
4864 bodyMesh2( &wmax, &vmax, &umax, x, y, z);
4865 for (u=1; u<umax-1; u++)
4866 {
4867 for (v=1; v<vmax-1; v++)
4868 {
4869 for (w=1; w<wmax-1; w++)
4870 {
4871 xn=x[u*vmax*wmax +v*wmax +w];
4872 yn=y[u*vmax*wmax +v*wmax +w];
4873 zn=z[u*vmax*wmax +v*wmax +w];
4874 sem_wait(&sem_n);
4875 nod( apre, &npre, 0, apre->nmax+1, xn, yn, zn, 0 );
4876 body[b_indx].nod[k]=n_uvw[u*vmax*wmax +v*wmax +w]=apre->nmax;
4877 sem_post(&sem_n);
4878
4879 #if TEST
4880 sprintf( buffer, "%d ", body[b_indx].nod[k]);
4881 sprintf( namebuf, "bod%d ", b_indx);
4882 sem_wait(&sem_g);
4883 pre_seta( namebuf, "n", buffer);
4884 sem_post(&sem_g);
4885 #endif
4886
4887 k++;
4888 }
4889 }
4890 }
4891 body[b_indx].nn=k;
4892 body[b_indx].fail=0;
4893
4894 free(x);
4895 free(y);
4896 free(z);
4897 free(div_l);
4898 return(1);
4899 }
4900
4901
4902 /**********************************************************************************/
4903 /* */
4904 /* bestimme die parametrischen Kantenlaengen der surf eines bodies */
4905 /* */
4906 /* */
4907 /* in: */
4908 /* b body -index */
4909 /* s surface-index in body-def */
4910 /* */
4911 /* out: */
4912 /* div_l divisions of all surf-edges */
4913 /* */
4914 /* return: */
4915 /* unbalance 1: unbalanced edges, 0: balanced edges, -1 not meshable */
4916 /* */
4917 /**********************************************************************************/
getSurfDivs(int b,int s,int * div_l)4918 int getSurfDivs( int b, int s, int *div_l )
4919 {
4920 int j, n, k, l, m;
4921 int sum_div;
4922
4923 j=body[b].s[s];
4924
4925 /* determine the amount of nodes in the surf without the nodes of the borderlines and points */
4926 /* => div.side1-1 * div.side2-1 = amount of embeded nodes */
4927 for (n=0; n<surf[j].nl; n++)
4928 {
4929 k=surf[j].l[n];
4930 div_l[n]=0;
4931 if( surf[j].typ[n]=='c' )
4932 {
4933 for( l=0; l<lcmb[k].nl; l++ )
4934 {
4935 m=lcmb[k].l[l];
4936 div_l[n]+=line[m].div;
4937 }
4938 }
4939 else
4940 div_l[n]+=line[k].div;
4941 }
4942 /* look if the divisions are suited for the elemtype */
4943 /* sum_div%2=0 for linear elements */
4944 sum_div=0;
4945 if (body[b].etyp==1)
4946 {
4947 for (n=0; n<4; n++) sum_div+=div_l[n];
4948 if((sum_div&(int)1))
4949 {
4950 printf ("WARNING: bad divisions in body:%s\n", body[b].name);
4951 return(-1);
4952 }
4953 }
4954 /* check each div%2=0 for quadratic elems, and check if the sum_div%4=0 */
4955 if (body[b].etyp==4)
4956 {
4957 for (n=0; n<4; n++)
4958 {
4959 if((div_l[n]&(int)1))
4960 {
4961 printf ("WARNING: bad divisions in body:%s\n", body[b].name);
4962 return(-1);
4963 }
4964 sum_div+=div_l[n];
4965 }
4966 if( ((sum_div&(int)1))||((sum_div&(int)2)) )
4967 {
4968 printf ("WARNING: bad divisions in body:%s\n", body[b].name);
4969 return(-1);
4970 }
4971 }
4972 if ((div_l[0]!=div_l[2])||(div_l[1]!=div_l[3])) return(1);
4973 else return(0);
4974 }
4975
4976
4977 /**********************************************************************************/
4978 /* */
4979 /* calculates new positions for existing nodes to gain a better quality */
4980 /* */
4981 /* return 1 if bad elements exist else 0 */
4982 /* */
4983 /**********************************************************************************/
meshImprover(int * petyp,int * nodes,int * elements,int * n_indx,int * n_ori,double ** n_coord,int ** e_nod,int * n_type,int ** n_edge,int ** s_div)4984 int meshImprover( int *petyp, int *nodes, int *elements, int *n_indx, int *n_ori, double **n_coord, int **e_nod, int *n_type, int **n_edge, int **s_div )
4985 {
4986 int i,j,k,n, nn[6], nr_surfs;
4987
4988 Summen anzl[1];
4989 Nodes nodel[20];
4990
4991 /* workspace for the improver */
4992
4993 int *kon=NULL, *neigh=NULL, *iptr1=NULL, *iptr2=NULL, *nside=NULL, *ineino=NULL, *nkind=NULL;
4994 double *co=NULL, *pneigh=NULL;
4995 int ndiv[24], maxsumdiv;
4996 double xl[20][3];
4997 char elty[MAX_LINE_LENGTH];
4998 int checkFailed=0;
4999 int *etyp;
5000 int vetyp;
5001
5002 etyp=&vetyp;
5003 if (*petyp==7) *etyp=9;
5004 else if (*petyp==8) *etyp=9;
5005 else *etyp=*petyp;
5006
5007 if((kon=(int *)malloc( (int)(*elements*20)*sizeof(int)) )==NULL)
5008 { printf(" ERROR: kon malloc failure in meshImproverHe20\n\n"); return(-1); }
5009 if((iptr1=(int *)malloc( (int)*nodes*sizeof(int)) )==NULL)
5010 { printf(" ERROR: iptr1 malloc failure in meshImproverHe20\n\n"); return(-1); }
5011 if((iptr2=(int *)malloc( (int)(*nodes*6)*sizeof(int)) )==NULL)
5012 { printf(" ERROR: iptr2 malloc failure in meshImproverHe20\n\n"); return(-1); }
5013 if((nside=(int *)malloc( (int)(*nodes)*sizeof(int)) )==NULL)
5014 { printf(" ERROR: nside malloc failure in meshImproverHe20\n\n"); return(-1); }
5015 if((ineino=(int *)malloc( (int)(*nodes*12)*sizeof(int)) )==NULL)
5016 { printf(" ERROR: ineino malloc failure in meshImproverHe20\n\n"); return(-1); }
5017 if((nkind=(int *)malloc( (int)(*nodes)*sizeof(int)) )==NULL)
5018 { printf(" ERROR: nkind malloc failure in meshImproverHe20\n\n"); return(-1); }
5019
5020 if((pneigh=(double *)malloc( (int)(*nodes*3)*sizeof(double)) )==NULL)
5021 { printf(" ERROR: pneigh malloc failure in meshImproverHe20\n\n"); return(-1); }
5022 if((co=(double *)malloc( (int)(*nodes*3)*sizeof(double)) )==NULL)
5023 { printf(" ERROR: co malloc failure in meshImproverHe20\n\n"); return(-1); }
5024
5025 for (i=0; i<*nodes; i++)
5026 {
5027 nkind[i]=n_type[i+1];
5028 }
5029
5030 for (i=0; i<*nodes; i++)
5031 for (j=0; j<3; j++)
5032 co[i*3+j]=(double)n_coord[i][j];
5033
5034 if(*etyp==1)
5035 {
5036 nr_surfs=6;
5037 for (i=0; i<*elements; i++)
5038 {
5039 for (j=0; j<8; j++)
5040 kon[i*20+j]=e_nod[i][j];
5041 for (j=8; j<20; j++)
5042 kon[i*20+j]=0;
5043 }
5044 }
5045 else if(*etyp==4)
5046 {
5047 nr_surfs=6;
5048 for (i=0; i<*elements; i++)
5049 {
5050 for (j=0; j<12; j++)
5051 kon[i*20+j]=e_nod[i][j];
5052 for (j=12; j<16; j++)
5053 kon[i*20+j+4]=e_nod[i][j];
5054 for (j=16; j<20; j++)
5055 kon[i*20+j-4]=e_nod[i][j];
5056 }
5057 }
5058 else if(*etyp==9)
5059 {
5060 nr_surfs=1;
5061 for (i=0; i<*elements; i++)
5062 {
5063 for (j=0; j<4; j++)
5064 kon[i*20+j]=e_nod[i][j];
5065 for (j=4; j<20; j++)
5066 kon[i*20+j]=0;
5067 }
5068 }
5069 else if(*etyp==10)
5070 {
5071 nr_surfs=1;
5072 for (i=0; i<*elements; i++)
5073 {
5074 for (j=0; j<8; j++)
5075 kon[i*20+j]=e_nod[i][j];
5076 for (j=8; j<20; j++)
5077 kon[i*20+j]=0;
5078 }
5079 }
5080 else return(-1);
5081
5082 maxsumdiv=0;
5083 for (i=0; i<nr_surfs; i++)
5084 {
5085 nn[i]=0;
5086 for (j=0; j<4; j++) { nn[i]+=s_div[i][j]; }
5087 if(nn[i]>maxsumdiv) maxsumdiv=nn[i];
5088 }
5089 if((neigh=(int *)malloc( (int)(maxsumdiv*12)*sizeof(int)) )==NULL)
5090 { printf(" ERROR: neigh malloc failure in meshImproverHe20\n\n"); return(-1); }
5091 for (i=0; i<nr_surfs; i++)
5092 for (j=0; j<nn[i]; j++)
5093 neigh[i*maxsumdiv+j]=n_edge[i][j];
5094
5095
5096 for (i=0; i<nr_surfs; i++)
5097 for (j=0; j<4; j++)
5098 {
5099 ndiv[i*4+j]=s_div[i][j];
5100 }
5101
5102
5103 // sem_wait(&sem_n);
5104 if ((meshopt_length)||(oldmeshflag))
5105 smooth_length( co,nodes,kon,elements,iptr1,iptr2,nside,ineino,nkind,neigh,ndiv,pneigh,&maxsumdiv,etyp, n_ori);
5106 if (oldmeshflag) goto finish;
5107 if (meshopt_angle)
5108 smooth_angle( co,nodes,kon,elements,iptr1,iptr2,nside,ineino,nkind,neigh,ndiv,pneigh,&maxsumdiv,etyp, n_ori);
5109 //sem_post(&sem_n);
5110
5111 /* check the mesh for negative jacobian matrix */
5112 anzl->e=1;
5113 checkFailed=0;
5114 for (i=0; i<*elements; i++)
5115 {
5116 if(*etyp == 1)
5117 {
5118 for(j=0; j<8; j++)
5119 {
5120 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5121 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5122 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5123 }
5124 for(j=0; j<8; j++)
5125 {
5126 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5127 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5128 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5129 }
5130 for(j=0; j<8; j++)
5131 {
5132 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5133 }
5134 strcpy(elty,"C3D8");
5135 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5136 strcpy(elty,"C3D8R");
5137 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5138 }
5139 else if(*etyp == 4)
5140 {
5141 for(j=0; j<20; j++)
5142 {
5143 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5144 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5145 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5146 }
5147 for(j=0; j<20; j++)
5148 {
5149 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5150 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5151 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5152 }
5153
5154 for(j=0; j<12; j++)
5155 {
5156 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5157 }
5158 for(n=16; n<20; n++)
5159 {
5160 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5161 j++;
5162 }
5163 for(n=12; n<16; n++)
5164 {
5165 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5166 j++;
5167 }
5168 strcpy(elty,"C3D20");
5169 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5170 strcpy(elty,"C3D20R");
5171 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5172 }
5173 else if(*etyp == 6)
5174 {
5175 for(j=0; j<10; j++)
5176 {
5177 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5178 }
5179 strcpy(elty,"C3D10");
5180 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5181 }
5182 }
5183
5184 /* if negative jacobian matrix do smooth_length alone */
5185 if ((meshopt_length)&&(checkFailed))
5186 {
5187 printf ("WARNING: smooth_length only\n");
5188 smooth_length( co,nodes,kon,elements,iptr1,iptr2,nside,ineino,nkind,neigh,ndiv,pneigh,&maxsumdiv,etyp, n_ori);
5189 }
5190
5191 if (checkFailed)
5192 {
5193 /* check the mesh for negative jacobian matrix */
5194 checkFailed=0;
5195 for (i=0; i<*elements; i++)
5196 {
5197 if(*etyp == 1)
5198 {
5199 for(j=0; j<8; j++)
5200 {
5201 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5202 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5203 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5204 }
5205 for(j=0; j<8; j++)
5206 {
5207 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5208 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5209 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5210 }
5211
5212 for(j=0; j<8; j++)
5213 {
5214 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5215 }
5216 strcpy(elty,"C3D8");
5217 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5218 strcpy(elty,"C3D8R");
5219 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5220 }
5221 else if(*etyp == 4)
5222 {
5223 for(j=0; j<20; j++)
5224 {
5225 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5226 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5227 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5228 }
5229 for(j=0; j<20; j++)
5230 {
5231 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5232 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5233 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5234 }
5235
5236 for(j=0; j<12; j++)
5237 {
5238 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5239 }
5240 for(n=16; n<20; n++)
5241 {
5242 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5243 j++;
5244 }
5245 for(n=12; n<16; n++)
5246 {
5247 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5248 j++;
5249 }
5250 strcpy(elty,"C3D20");
5251 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5252 strcpy(elty,"C3D20R");
5253 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5254 }
5255 else if(*etyp == 6)
5256 {
5257 for(j=0; j<10; j++)
5258 {
5259 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5260 }
5261 strcpy(elty,"C3D10");
5262 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5263 }
5264 }
5265 }
5266
5267 /* if negative jacobian matrix do smooth_angle alone */
5268 if ((meshopt_angle)&&(checkFailed))
5269 {
5270 printf ("WARNING: smooth_angle only\n");
5271 smooth_angle( co,nodes,kon,elements,iptr1,iptr2,nside,ineino,nkind,neigh,ndiv,pneigh,&maxsumdiv,etyp, n_ori);
5272 }
5273
5274 if (checkFailed)
5275 {
5276 /* check the mesh for negative jacobian matrix */
5277 checkFailed=0;
5278 for (i=0; i<*elements; i++)
5279 {
5280 if(*etyp == 1)
5281 {
5282 for(j=0; j<8; j++)
5283 {
5284 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5285 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5286 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5287 }
5288 for(j=0; j<8; j++)
5289 {
5290 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5291 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5292 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5293 }
5294
5295 for(j=0; j<8; j++)
5296 {
5297 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5298 }
5299 strcpy(elty,"C3D8");
5300 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5301 strcpy(elty,"C3D8R");
5302 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5303 }
5304 else if(*etyp == 4)
5305 {
5306 for(j=0; j<20; j++)
5307 {
5308 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5309 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5310 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5311 }
5312 for(j=0; j<20; j++)
5313 {
5314 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5315 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5316 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5317 }
5318
5319 for(j=0; j<12; j++)
5320 {
5321 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5322 }
5323 for(n=16; n<20; n++)
5324 {
5325 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5326 j++;
5327 }
5328 for(n=12; n<16; n++)
5329 {
5330 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5331 j++;
5332 }
5333 strcpy(elty,"C3D20");
5334 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5335 strcpy(elty,"C3D20R");
5336 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5337 }
5338 else if(*etyp == 6)
5339 {
5340 for(j=0; j<10; j++)
5341 {
5342 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5343 }
5344 strcpy(elty,"C3D10");
5345 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5346 }
5347 }
5348 }
5349
5350 /* if negative jacobian matrix do smooth_midnodes alone */
5351 if ((checkFailed) || (!meshopt_angle && !meshopt_length))
5352 {
5353 for (i=0; i<*nodes; i++)
5354 for (j=0; j<3; j++)
5355 co[i*3+j]=(double)n_coord[i][j];
5356 printf ("WARNING: no smoothing\n");
5357 smooth_midnodes( co,nodes,kon,elements,iptr1,iptr2,nside,ineino,nkind,neigh,ndiv,pneigh,&maxsumdiv,etyp, n_ori);
5358 }
5359
5360 if (checkFailed)
5361 {
5362 /* check the mesh for negative jacobian matrix */
5363 checkFailed=0;
5364 for (i=0; i<*elements; i++)
5365 {
5366 if(*etyp == 1)
5367 {
5368 for(j=0; j<8; j++)
5369 {
5370 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5371 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5372 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5373 }
5374 for(j=0; j<8; j++)
5375 {
5376 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5377 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5378 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5379 }
5380
5381 for(j=0; j<8; j++)
5382 {
5383 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5384 }
5385 strcpy(elty,"C3D8");
5386 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5387 strcpy(elty,"C3D8R");
5388 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5389 }
5390 else if(*etyp == 4)
5391 {
5392 for(j=0; j<20; j++)
5393 {
5394 nodel[j].nx=co[3*(e_nod[i][j]-1)+0];
5395 nodel[j].ny=co[3*(e_nod[i][j]-1)+1];
5396 nodel[j].nz=co[3*(e_nod[i][j]-1)+2];
5397 }
5398 for(j=0; j<20; j++)
5399 {
5400 co[3*(e_nod[i][j]-1)+0]=nodel[j].nx;
5401 co[3*(e_nod[i][j]-1)+1]=nodel[j].ny;
5402 co[3*(e_nod[i][j]-1)+2]=nodel[j].nz;
5403 }
5404
5405 for(j=0; j<12; j++)
5406 {
5407 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5408 }
5409 for(n=16; n<20; n++)
5410 {
5411 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5412 j++;
5413 }
5414 for(n=12; n<16; n++)
5415 {
5416 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][n]-1)+k];
5417 j++;
5418 }
5419 strcpy(elty,"C3D20");
5420 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5421 strcpy(elty,"C3D20R");
5422 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5423 }
5424 else if(*etyp == 6)
5425 {
5426 for(j=0; j<10; j++)
5427 {
5428 for(k=0; k<3; k++) xl[j][k]= co[3*(e_nod[i][j]-1)+k];
5429 }
5430 strcpy(elty,"C3D10");
5431 if (!e_c3d__(&xl[0][0], elty)) checkFailed=1;
5432 }
5433 }
5434 }
5435
5436 finish:;
5437 for (i=0; i<*nodes; i++)
5438 {
5439 for (j=0; j<3; j++)
5440 {
5441 n_coord[i][j]=co[i*3+j];
5442 }
5443 }
5444 free(kon);
5445 free(neigh);
5446 free(iptr1);
5447 free(iptr2);
5448 free(nside);
5449 free(ineino);
5450 free(nkind);
5451 free(co);
5452 free(pneigh);
5453
5454 return(checkFailed);
5455 }
5456
5457
5458
5459
bodyFrom5Surfs(int * b)5460 int bodyFrom5Surfs( int *b)
5461 {
5462 int i,ii,j,jj,k,l,n,s, **sn=NULL, u,v, umax,vmax;
5463 int bs; /* body-surf */
5464 int lm[2]; /* master-lines which are replaced by lines ls */
5465 int tm[2]; /* master-line-type which is replaced by lines ls */
5466 int ss[6]; /* slave surfs */
5467 int ps[2]; /* split points */
5468 int ls[2][2]; /* lines ls[surf][l] in the place of the master-lines */
5469 int ts[2][2]; /* type of lines ls[surf][l] in the place of the master-lines */
5470 int sm[2]; /* surface between 0 and 1 which is to be replaced by two new ones */
5471 int lm2[2]; /* master-lines which are located between surf 0 and 1 */
5472 int tm2[2]; /* master-lines-type which are located between surf 0 and 1 */
5473 int om2[2]; /* master-lines-ori which are located between surf 0 and 1 */
5474 int lnew; /* line between split-points */
5475
5476 int clin[MAX_EDGES_PER_SURF], l1, l3;
5477 int edge[MAX_EDGES_PER_SURF];
5478 char ctyp[MAX_EDGES_PER_SURF];
5479 char cori[MAX_SURFS_PER_BODY]; /* orientation, used for slave surfs and body */
5480
5481 int lnew_[2];
5482 char typnew[2];
5483
5484 char name[MAX_LINE_LENGTH];
5485
5486
5487 /* store the basic info from the substitute surfs */
5488 for(bs=0; bs<2; bs++)
5489 {
5490 s=body[*b].s[bs];
5491 lm[bs]=surf[s].l[surf[s].l[3]];
5492 tm[bs]=surf[s].typ[surf[s].l[3]];
5493 ss[bs]=surf[s].l[4];
5494 ps[bs]=surf[s].l[5];
5495 ls[bs][0]=surf[s].l[6];
5496 ts[bs][0]=surf[s].l[7];
5497 ls[bs][1]=surf[s].l[8];
5498 ts[bs][1]=surf[s].l[9];
5499
5500 /* search the surf sm (no. 2,3,4) which is related to the replaced line lm */
5501 for(i=2; i<5; i++)
5502 {
5503 sm[bs]=body[*b].s[i];
5504 for(j=0; j<4; j++) if((surf[sm[bs]].l[j]==lm[bs])&&(surf[sm[bs]].typ[j]==tm[bs])) goto sm_found;
5505 }
5506 sm_found:;
5507 }
5508
5509 /* this surfaces should be identical if the geometry was sweped */
5510 if(sm[0]!=sm[1])
5511 {
5512 /* the embedded surface ss[1] must be redefined. */
5513 printf("WARNING: Untested code in bodyFrom5Surfs()\n");
5514
5515 /* search the opposide line to lm[0] on surf sm[1]. This is also part of surf =body[*b].s[1] */
5516 printf("the embedded surface ss[1] must be redefined lm[0]:%s lm[1]:%s\n", line[lm[0]].name, line[lm[1]].name);
5517 lm[1]=-1;
5518 s=body[*b].s[1];
5519 for(i=0; i<3; i++)
5520 for(j=0; j<4; j++)
5521 if((surf[sm[1]].l[j]==surf[s].l[i])&&(surf[sm[1]].typ[j]==surf[s].typ[i]))
5522 { lm[1]=surf[s].l[i]; goto foundLine; }
5523 printf("ERROR: line opposide to lm[0] not found\n");
5524 foundLine:;
5525 printf("new lm[1]:%s\n", line[lm[1]].name);
5526 if(lm[1]==-1) { printf(" ERROR: 5-sided body not meshable\n"); return(-1); }
5527
5528 ps[1]=splitLineAtDivratio( surf[s].l[i], surf[s].typ[i], 0.5, lnew_, typnew);
5529 if (ps[1]==-1) { printf(" ERROR: 5-sided body not meshable\n"); return(-1); }
5530
5531 /* create a 4 sided surf */
5532 for (jj=0; jj<i; jj++)
5533 {
5534 edge[jj]=surf[s].l[jj];
5535 cori[jj]=surf[s].o[jj];
5536 ctyp[jj]=surf[s].typ[jj];
5537 }
5538 edge[jj]=lnew_[0];
5539 cori[jj]=surf[s].o[2];
5540 ctyp[jj]=typnew[0];
5541 jj++;
5542 edge[jj]=lnew_[1];
5543 cori[jj]=surf[s].o[2];
5544 ctyp[jj]=typnew[1];
5545 for (; jj<3; jj++) /* thats ok so */
5546 {
5547 edge[jj+1]=surf[s].l[jj];
5548 cori[jj+1]=surf[s].o[jj];
5549 ctyp[jj+1]=surf[s].typ[jj];
5550 }
5551
5552 #if TEST
5553 for (jj=0; jj<MAX_EDGES_PER_SURF; jj++)
5554 {
5555 if(ctyp[jj]=='l') printf("edge:%s cori:%c ctyp:%c\n", line[edge[jj]].name, cori[jj], ctyp[jj]);
5556 else if(ctyp[jj]=='c') printf("edge:%s cori:%c ctyp:%c\n", lcmb[edge[jj]].name, cori[jj], ctyp[jj]);
5557 else printf("error:%c\n",ctyp[jj]);
5558 }
5559 #endif
5560 ss[1]=surface_i( surf[ss[1]].name, surf[s].ori, -1, MAX_EDGES_PER_SURF, cori, edge, ctyp );
5561 if( ss[1]<0)
5562 { printf("ERROR: surface could not be created\n"); return(-1); }
5563 setr( 0, "s",ss[1] );
5564 surf[ss[1]].etyp=surf[s].etyp;
5565 /* update the reference to the substitute-surface (s) */
5566 surf[s].l[surf[s].nl]=i ;
5567 surf[s].l[surf[s].nl+1]=ss[1];
5568 surf[s].l[surf[s].nl+2]=ps[1];
5569 surf[s].l[surf[s].nl+3]=ls[1][0]=lnew_[0];
5570 surf[s].l[surf[s].nl+4]=ts[1][0]=typnew[0];
5571 surf[s].l[surf[s].nl+5]=ls[1][1]=lnew_[1];
5572 surf[s].l[surf[s].nl+6]=ts[1][1]=typnew[1];
5573
5574 if(printFlag) printf("surf[%d]:%s is replaced by surf[%d]:%s\n",j, surf[s].name,s, surf[ss[1]].name);
5575
5576 /* the embedded nodes must be rearranged to meet the toplology of the new slave surf */
5577 /* allocate memory for embeded nodes */
5578 if((surf[ss[1]].nod=(int *)realloc((int *)surf[ss[1]].nod, surf[s].nn*sizeof(int)) )==NULL)
5579 { printf(" ERROR: realloc failure in meshSurfs surf:%s can not be meshed, surf->nod (3)\n\n", surf[ss[1]].name);
5580 return(-1); }
5581
5582 /* map the nodes */
5583 /* WARNING: this straight forward mapping is not supposed to work but it works thanks to the meshimprover. */
5584 /* the changed u,v range is not considered, the necessary order is differend and should be updated */
5585 surf[ss[1]].nn=surf[s].nn;
5586 for(j=0; j<surf[ss[1]].nn; j++) surf[ss[1]].nod[j]=surf[s].nod[j];
5587 }
5588 #if TEST
5589 for(bs=0; bs<2; bs++)
5590 {
5591 printf("ps:%s sm:%s ss:%s\n", point[ps[bs]].name, surf[sm[bs]].name, surf[ss[bs]].name);
5592 if(tm[bs]=='c') printf("cm:%s\n", lcmb[lm[bs]].name );
5593 if(tm[bs]=='l') printf("lm:%s\n", line[lm[bs]].name );
5594 if(ts[bs][0]=='c') printf("cs:%s\n", lcmb[ls[bs][0]].name );
5595 if(ts[bs][0]=='l') printf("ls:%s\n", line[ls[bs][0]].name );
5596 if(ts[bs][1]=='c') printf("cs:%s\n", lcmb[ls[bs][1]].name );
5597 if(ts[bs][1]=='l') printf("ls:%s\n", line[ls[bs][1]].name );
5598 }
5599 #endif
5600
5601 /* replace this surf sm by two new ones ss[4 and 5] and map the nodes into them */
5602 /* search the remaining unknown lines between ss 0 and 1 */
5603 j=0; for(i=0; i<surf[sm[0]].nl; i++)
5604 {
5605 /* if the lines are not lm[] */
5606 if( ((surf[sm[0]].typ[i]==tm[0])&&(surf[sm[0]].l[i]==lm[0])) || ((surf[sm[0]].typ[i]==tm[1])&&(surf[sm[0]].l[i]==lm[1])) );
5607 else
5608 {
5609 tm2[j]=surf[sm[0]].typ[i];
5610 om2[j]=surf[sm[0]].o[i];
5611 lm2[j]=surf[sm[0]].l[i];
5612 #if TEST
5613 if(tm2[j]=='l') printf("%d line between sur0,1:%s\n", j,line[lm2[j]].name);
5614 else if(tm2[j]=='c') printf("%d lcmb between sur0,1:%s\n", j,lcmb[lm2[j]].name);
5615 else printf("%d typ:%c not known, lm2:%d\n", j, tm2[j],lm2[j] );
5616 #endif
5617 j++;
5618 }
5619 }
5620 /* create a line between ps and fill it with nodes from sm */
5621 getNewName( name, "l" );
5622 lnew= line_i( name, ps[0], ps[1], -1, line[lm2[0]].div, 1, 0 );
5623 if(lnew<0) { printf("ERROR: line could not be created\n"); return(-1); }
5624 pre_seta(specialset->zap, "l", name);
5625
5626 /* create the surfs ss 4 and 5 */
5627 /* the 0. line of the slave surfs correspond to lm2 and the orientation also */
5628 /* look which ls are connected to lm2 */
5629 for(i=0; i<2; i++) /* two surfs inside sm[0] */
5630 {
5631 #if TEST
5632 printf(" create new surf\n");
5633 #endif
5634 if((tm2[i]!='l')&&(tm2[i]!='c'))
5635 {
5636 printf("ERROR: body:%s could not be meshed\n", body[*b].name);
5637 return(-1);
5638 }
5639
5640 if(om2[i]=='-') { l1=1; l3=3; }
5641 else { l1=3; l3=1; }
5642 for(j=0; j<2; j++) /* left and right side of sm */
5643 {
5644 for(l=0; l<2; l++) /* two lines on each side */
5645 {
5646 if(tm2[i]=='l')
5647 {
5648 if(ts[j][l]=='l')
5649 {
5650 if((line[lm2[i]].p1==line[ls[j][l]].p1)||(line[lm2[i]].p1==line[ls[j][l]].p2))
5651 {
5652 clin[l1]=ls[j][l];
5653 ctyp[l1]=ts[j][l];
5654 }
5655 if((line[lm2[i]].p2==line[ls[j][l]].p1)||(line[lm2[i]].p2==line[ls[j][l]].p2))
5656 {
5657 clin[l3]=ls[j][l];
5658 ctyp[l3]=ts[j][l];
5659 }
5660 }
5661 if(ts[j][l]=='c')
5662 {
5663 if((line[lm2[i]].p1==lcmb[ls[j][l]].p1)||( line[lm2[i]].p1==lcmb[ls[j][l]].p2))
5664 {
5665 clin[l1]=ls[j][l];
5666 ctyp[l1]=ts[j][l];
5667 }
5668 if((line[lm2[i]].p2==lcmb[ls[j][l]].p1)||( line[lm2[i]].p2==lcmb[ls[j][l]].p2))
5669 {
5670 clin[l3]=ls[j][l];
5671 ctyp[l3]=ts[j][l];
5672 }
5673 }
5674 }
5675 if(tm2[i]=='c')
5676 {
5677 if(ts[j][l]=='l')
5678 {
5679 if((lcmb[lm2[i]].p1==line[ls[j][l]].p1)||( lcmb[lm2[i]].p1==line[ls[j][l]].p2))
5680 {
5681 clin[l1]=ls[j][l];
5682 ctyp[l1]=ts[j][l];
5683 }
5684 if((lcmb[lm2[i]].p2==line[ls[j][l]].p1)||( lcmb[lm2[i]].p2==line[ls[j][l]].p2))
5685 {
5686 clin[l3]=ls[j][l];
5687 ctyp[l3]=ts[j][l];
5688 }
5689 }
5690 if(ts[j][l]=='c')
5691 {
5692 if((lcmb[lm2[i]].p1==lcmb[ls[j][l]].p1)||( lcmb[lm2[i]].p1==lcmb[ls[j][l]].p2))
5693 {
5694 clin[l1]=ls[j][l];
5695 ctyp[l1]=ts[j][l];
5696 }
5697 if((lcmb[lm2[i]].p2==lcmb[ls[j][l]].p1)||( lcmb[lm2[i]].p2==lcmb[ls[j][l]].p2))
5698 {
5699 clin[l3]=ls[j][l];
5700 ctyp[l3]=ts[j][l];
5701 }
5702 }
5703 }
5704 }
5705 }
5706
5707 clin[0]=lm2[i];
5708 ctyp[0]=tm2[i];
5709 clin[2]=lnew;
5710 ctyp[2]='l';
5711 for(j=0; j<6; j++) cori[j]='+';
5712 #if TEST
5713 for(j=0; j<4; j++)
5714 {
5715 if(ctyp[j]=='l')printf("clin[%d]:%s ctyp:%c cori:%c\n", j, line[clin[j]].name,ctyp[j],cori[j]);
5716 else if(ctyp[j]=='c')printf("clin[%d]:%s ctyp:%c cori:%c\n", j, lcmb[clin[j]].name,ctyp[j],cori[j]);
5717 else printf("typ:%c not known, clin:%d cori:%c\n", ctyp[j],clin[j],cori[j] );
5718 }
5719 #endif
5720 getNewName( name, "s" );
5721 ss[i+4]= surface_i( name, surf[sm[0]].ori, -1, 4, cori, clin, ctyp );
5722 if(ss[i+4]<0)
5723 {
5724 printf("ERROR: surf could not be created\n");
5725 return(-1);
5726 }
5727 //setr( 0, "s", ss[i+4] );
5728 pre_seta(specialset->zap, "s", name);
5729
5730 /* map the nodes of the master to the slave */
5731 /* determine the div of the surf umax and vmax */
5732 k=surf[sm[0]].l[0];
5733 umax=0;
5734 if( surf[sm[0]].typ[0]=='l' ) umax=line[k].div;
5735 else for( l=0; l<lcmb[k].nl; l++ ) umax+=line[lcmb[k].l[l]].div;
5736 k=surf[sm[0]].l[3];
5737 vmax=0;
5738 if( surf[sm[0]].typ[3]=='l' ) vmax=line[k].div;
5739 else for( l=0; l<lcmb[k].nl; l++ ) vmax+=line[lcmb[k].l[l]].div;
5740
5741 if((sn = (int **)malloc((umax+1)*sizeof(int *))) == NULL )
5742 errMsg(" ERROR: malloc failed in bodyFrom5Surfs()\n");
5743 for(k=0; k<(umax+1); k++)
5744 {
5745 if((sn[k] = (int *)malloc((vmax+1)*sizeof(int))) == NULL )
5746 errMsg(" ERROR: malloc failed in bodyFrom5Surfs()\n");
5747 }
5748
5749 /* map the master-surf-nodes in a prelim-area */
5750
5751 /* define the division of surf[].l[1] which is aligned to lm[]. */
5752 /* this is necessary to determine the ratio of nodes of both slave surfs */
5753 if(surf[ss[i+4]].typ[1]=='l') ii=line[surf[ss[i+4]].l[1]].div;
5754 else
5755 {
5756 ii=0;
5757 for(u=0; u<lcmb[surf[ss[i+4]].l[1]].nl; u++)
5758 {
5759 ii+=line[lcmb[surf[ss[i+4]].l[1]].l[u]].div;
5760 }
5761 }
5762 j=0; for (u=1; u<umax; u++)
5763 {
5764 for (v=1; v<vmax; v++)
5765 {
5766 sn[u][v]=surf[sm[0]].nod[j];
5767 j++;
5768 }
5769 }
5770
5771 j=0;
5772 if((lm2[i]==surf[sm[0]].l[0])&&(tm2[i]==surf[sm[0]].typ[0]))
5773 {
5774 if((surf[ss[i+4]].nod=(int *)realloc((int *)surf[ss[i+4]].nod, (umax*vmax/2+1)*sizeof(int)) )==NULL)
5775 errMsg(" ERROR: malloc failure\n");
5776 for (u=1; u<umax; u++)
5777 {
5778 for (v=1; v<ii; v++)
5779 {
5780 surf[ss[i+4]].nod[j]=sn[u][v];
5781 /* printf("ns00[%d][%d]:%d\n", u,v,sn[u][v]); */
5782 j++;
5783 }
5784 }
5785 /* add nodes to the new line */
5786 if ((line[lnew].nod = (int *)realloc( (int *)line[lnew].nod, (umax+1)*sizeof(int)) ) == NULL )
5787 errMsg(" ERROR: malloc failure\n");
5788 n=0; if(surf[ss[i+4]].o[2]=='+')
5789 {
5790 for (u=umax-1; u>0; u--) { line[lnew].nod[n]= sn[u][ii]; n++; }
5791 }
5792 else
5793 {
5794 for (u=1; u<umax; u++) { line[lnew].nod[n]= sn[u][ii]; n++; }
5795 }
5796 line[lnew].nn=n;
5797 }
5798 if((lm2[i]==surf[sm[0]].l[1])&&(tm2[i]==surf[sm[0]].typ[1]))
5799 {
5800 if((surf[ss[i+4]].nod=(int *)realloc((int *)surf[ss[i+4]].nod, (umax/2*vmax+1)*sizeof(int)) )==NULL)
5801 errMsg(" ERROR: malloc failure\n");
5802 for (v=1; v<vmax; v++)
5803 {
5804 for (u=umax-1; u>(umax-ii); u--)
5805 {
5806 surf[ss[i+4]].nod[j]=sn[u][v];
5807 j++;
5808 }
5809 }
5810 /* add nodes to the new line */
5811 if ((line[lnew].nod = (int *)realloc( (int *)line[lnew].nod, (vmax+1)*sizeof(int)) ) == NULL )
5812 errMsg(" ERROR: malloc failure\n");
5813 n=0; if(surf[ss[i+4]].o[2]=='+')
5814 {
5815 for (v=vmax-1; v>0; v--) { line[lnew].nod[n]= sn[umax-ii][v]; n++; }
5816 }
5817 else
5818 {
5819 for (v=1; v<vmax; v++) { line[lnew].nod[n]= sn[umax-ii][v]; n++; }
5820 }
5821 line[lnew].nn=n;
5822 }
5823 if((lm2[i]==surf[sm[0]].l[2])&&(tm2[i]==surf[sm[0]].typ[2]))
5824 {
5825 if((surf[ss[i+4]].nod=(int *)realloc((int *)surf[ss[i+4]].nod, (umax*vmax/2+1)*sizeof(int)) )==NULL)
5826 errMsg(" ERROR: malloc failure\n");
5827 for (u=umax-1; u>0; u--)
5828 {
5829 for (v=vmax-1; v>(vmax-ii); v--)
5830 {
5831 surf[ss[i+4]].nod[j]=sn[u][v];
5832 j++;
5833 }
5834 }
5835 }
5836 if((lm2[i]==surf[sm[0]].l[3])&&(tm2[i]==surf[sm[0]].typ[3]))
5837 {
5838 if((surf[ss[i+4]].nod=(int *)realloc((int *)surf[ss[i+4]].nod, (umax/2*vmax+1)*sizeof(int)) )==NULL)
5839 errMsg(" ERROR: malloc failure\n");
5840 for (v=vmax-1; v>0; v--)
5841 {
5842 for (u=1; u<ii; u++)
5843 {
5844 surf[ss[i+4]].nod[j]=sn[u][v];
5845 j++;
5846 }
5847 }
5848 }
5849 surf[ss[i+4]].nn=j;
5850
5851 for(k=0; k<(umax+1); k++) free(sn[k]);
5852 free(sn);
5853 }
5854
5855 /* create a new body with this surfs */
5856 j=2; for(i=2; i<5; i++)
5857 {
5858 if(body[*b].s[i]==sm[0]) { ss[j]=ss[4]; j++; ss[j]=ss[5]; }
5859 else ss[j]=body[*b].s[i];
5860 j++;
5861 }
5862 #if TEST
5863 for(i=0; i<6; i++)
5864 {
5865 printf("body: s:%s c:%c\n", surf[ss[i]].name, cori[i]);
5866 }
5867 #endif
5868 getNewName( name, "b" );
5869 bs= gbod_i( name, -1, 6, cori, ss );
5870 if(bs<0) { printf("ERROR: body could not be created\n"); return(-1); }
5871 setr(0,"b",bs);
5872 pre_seta(specialset->zap, "b", name);
5873 body[bs].etyp=body[*b].etyp;
5874 body[bs].eattr=body[*b].eattr;
5875 *b=bs;
5876 return(1);
5877 }
5878
5879
bodyFrom7Surfs(int * b)5880 int bodyFrom7Surfs( int *b)
5881 {
5882 int i,j,jj,k,l,n,s, **sn=NULL, u,v, umax0,umax1,vmax0,vmax1, ps=-1;
5883 int bs; /* body-surf */
5884 int lm[2][2]; /* master-lines which are replaced by lines ls */
5885 int tm[2][2]; /* master-line-type which is replaced by lines ls */
5886 int ss[6]; /* slave surfs */
5887 int cs[2]; /* lcmb cs[surf] in the place of the master-lines */
5888 int sm[2][2]; /* surfaces between 0 and 1 which are to be replaced by a new one */
5889
5890 int sml[2][4]; /* either 0 or 1 if the line is identified by lm or lcomon, lm2 are the remainders which are not connected with lcommon */
5891 int lm2[2]={0,0}; /* line-index of the lines between surf 0 and 1 which are needed for ss */
5892 int tm2[2]={0,0}; /* line-type of the lines between surf 0 and 1 which are needed for ss */
5893 int cl[2];
5894
5895 int tcomon=0, lcomon=0; /* line between sm */
5896 int clin[5];
5897 int edge[5];
5898 char ctyp[5];
5899 char cori[MAX_SURFS_PER_BODY]; /* orientation, used for slave surfs and body */
5900
5901 char name[MAX_LINE_LENGTH];
5902
5903
5904 /* store the basic info from the substitute surfs */
5905 for(bs=0; bs<2; bs++)
5906 {
5907 s=body[*b].s[bs];
5908 lm[bs][0]=surf[s].l[surf[s].l[5]];
5909 tm[bs][0]=surf[s].typ[surf[s].l[5]];
5910 lm[bs][1]=surf[s].l[surf[s].l[6]];
5911 tm[bs][1]=surf[s].typ[surf[s].l[6]];
5912 ss[bs]=surf[s].l[7];
5913 cs[bs]=surf[s].l[8];
5914 #if TEST
5915 printf("s:%d = %s\n", s, surf[s].name);
5916 printf("tm0:%c tm1:%c l5:%d l6:%d\n",tm[bs][0], tm[bs][1], surf[s].l[5],surf[s].l[6] );
5917 if(tm[bs][0]=='c') printf(" cm0:%s\n", lcmb[lm[bs][0]].name );
5918 if(tm[bs][0]=='l') printf(" lm0:%s\n", line[lm[bs][0]].name );
5919 if(tm[bs][1]=='c') printf(" cm1:%s\n", lcmb[lm[bs][1]].name );
5920 if(tm[bs][1]=='l') printf(" lm1:%s\n", line[lm[bs][1]].name );
5921 printf(" ss[%d]:%s\n", ss[bs], surf[ss[bs]].name);
5922 printf(" cs[%d]:%s\n", cs[bs], lcmb[cs[bs]].name );
5923 #endif
5924 }
5925
5926 /* search the two surfs sm between the 5-sided surfs which are related to the lm[0][0 and 1] */
5927 for(bs=0; bs<2; bs++)
5928 {
5929 n=0;
5930 sm1_found:;
5931 for(i=2; i<7; i++) /* all possible surfs of the body */
5932 {
5933 sm[bs][n]=body[*b].s[i];
5934 for(k=0; k<surf[sm[bs][n]].nl; k++) /* compare with all lines/lcmb in this surf */
5935 {
5936 #if TEST
5937 printf("bs:%d k:%d n:%d check line:%s i:%d with i:%d of typ:%c\n", bs, k, n, line[surf[sm[bs][n]].l[k]].name, surf[sm[bs][n]].l[k], lm[bs][n], tm[bs][n]);
5938 #endif
5939 if((surf[sm[bs][n]].l[k]==lm[bs][n])&&(surf[sm[bs][n]].typ[k]==tm[bs][n]))
5940 {
5941 sml[bs][k]=1; /* mark the line as known */
5942 #if TEST
5943 if(surf[sm[bs][n]].typ[k]=='l') printf("found surf:%s at line:%s\n", surf[sm[bs][n]].name, line[surf[sm[bs][n]].l[k]].name);
5944 if(surf[sm[bs][n]].typ[k]=='c') printf("found surf:%s at lcmb:%s\n", surf[sm[bs][n]].name, lcmb[surf[sm[bs][n]].l[k]].name);
5945 #endif
5946 n++;
5947 if(n==1) goto sm1_found;
5948 else goto sm2_found;
5949 }
5950 }
5951 }
5952 sm2_found:;
5953 }
5954
5955 /* compare the connected surfs */
5956 jj=0; for(i=0; i<2; i++) for(j=0; j<2; j++) if(sm[0][i]==sm[1][j]) jj++;
5957
5958 if(jj!=2)
5959 {
5960 /* the embedded surface ss[1] must be redefined. */
5961
5962 /* this works only if the number of embedded nodes of body[*b].s[0] and body[*b].s[1] are equal */
5963 /* to overcome this problem a remeshing of one of this surfs would be necessary, but then already */
5964 /* created elements based on this surface would not fit */
5965 if(surf[body[*b].s[0]].nn!=surf[body[*b].s[1]].nn)
5966 { printf(" ERROR: 7-sided body not meshable, the distortion is probably to big\n"); return(-1); }
5967
5968 /* search the corresponding line to lm[0] on surf sm[0][0]. This is also part of surf =body[*b].s[1] */
5969 cl[0]=cl[1]=-1;
5970 s=body[*b].s[1];
5971 for(i=0; i<5; i++)
5972 for(j=0; j<4; j++)
5973 if((surf[sm[0][0]].l[j]==surf[s].l[i])&&(surf[sm[0][0]].typ[j]==surf[s].typ[i]))
5974 { cl[0]=i; goto foundLine0; }
5975 foundLine0:;
5976 if(cl[0]==-1) { printf(" ERROR: 7-sided body not meshable 0\n"); return(-1); }
5977 for(i=0; i<5; i++)
5978 for(j=0; j<4; j++)
5979 if((surf[sm[0][1]].l[j]==surf[s].l[i])&&(surf[sm[0][1]].typ[j]==surf[s].typ[i]))
5980 { cl[1]=i; goto foundLine1; }
5981 foundLine1:;
5982 if(cl[1]==-1) { printf(" ERROR: 7-sided body not meshable 1\n"); return(-1); }
5983
5984 /* create a lcmb out of 2 edges */
5985 cs[1]=addTwoLines( surf[s].l[cl[0]], surf[s].o[cl[0]], surf[s].typ[cl[0]], surf[s].l[cl[1]], surf[s].l[cl[1]], surf[s].typ[cl[1]] );
5986 if( cs[1]==-1) { printf(" ERROR: 7-sided body not meshable 2\n"); return(-1); };
5987
5988 /* create a 4 sided surf */
5989 if (cl[0]==4)
5990 {
5991 edge[0]=cs[1];
5992 cori[0]=surf[s].o[cl[0]];
5993 ctyp[0]='c';
5994 for (jj=1; jj<cl[0]; jj++)
5995 {
5996 edge[jj]=surf[s].l[jj];
5997 cori[jj]=surf[s].o[jj];
5998 ctyp[jj]=surf[s].typ[jj];
5999 }
6000 }
6001 else
6002 {
6003 for (jj=0; jj<cl[0]; jj++)
6004 {
6005 edge[jj]=surf[s].l[jj];
6006 cori[jj]=surf[s].o[jj];
6007 ctyp[jj]=surf[s].typ[jj];
6008 }
6009 edge[jj]=cs[1];
6010 cori[jj]=surf[s].o[cl[0]];
6011 ctyp[jj]='c';
6012 for (jj++; jj<4; jj++)
6013 {
6014 edge[jj]=surf[s].l[jj+1];
6015 cori[jj]=surf[s].o[jj+1];
6016 ctyp[jj]=surf[s].typ[jj+1];
6017 }
6018 }
6019 #if TEST
6020 for (jj=0; jj<MAX_EDGES_PER_SURF; jj++)
6021 {
6022 if((ctyp[jj]!='l')&&(ctyp[jj]!='c'))
6023 { printf("ERROR: body:%s could not be meshed\n", body[*b].name); return(-1); }
6024 if(ctyp[jj]=='l') printf("edge:%s cori:%c ctyp:%c\n", line[edge[jj]].name, cori[jj], ctyp[jj]);
6025 else if(ctyp[jj]=='c') printf("edge:%s cori:%c ctyp:%c\n", lcmb[edge[jj]].name, cori[jj], ctyp[jj]);
6026 else printf("error:%c\n",ctyp[jj]);
6027 }
6028 #endif
6029 ss[1]=surface_i( surf[ss[1]].name, surf[ss[1]].ori, -1, MAX_EDGES_PER_SURF, cori, edge, ctyp );
6030 if(ss[1]<0) { printf("ERROR: surf could not be created\n"); return(-1); }
6031 setr( 0, "s", ss[1] );
6032 surf[ss[1]].etyp=surf[s].etyp;
6033
6034 surf[s].l[5]=cl[0]; /* place of the line in the surf */
6035 surf[s].l[6]=cl[1]; /* place of the line in the surf */
6036 surf[s].l[7]=ss[1]; /* slave surf */
6037 surf[s].l[8]=cs[1]; /* slave lcmb */
6038
6039 lm[1][0]=surf[s].l[surf[s].l[5]];
6040 tm[1][0]=surf[s].typ[surf[s].l[5]];
6041 lm[1][1]=surf[s].l[surf[s].l[6]];
6042 tm[1][1]=surf[s].typ[surf[s].l[6]];
6043
6044 if(printFlag) printf("surf:%s is replaced by surf:%s\n", surf[s].name, surf[ss[1]].name);
6045
6046 /* the embedded nodes must be rearranged to meet the toplology of the new slave surf */
6047 /* allocate memory for embeded nodes */
6048 if((surf[ss[1]].nod=(int *)realloc((int *)surf[ss[1]].nod, surf[s].nn*sizeof(int)) )==NULL)
6049 { printf(" ERROR: realloc failure in bodyFrom7Surfs surf:%s can not be meshed, surf->nod (4)\n\n", surf[ss[1]].name);
6050 return(-1); }
6051
6052 /* map the nodes */
6053 /* WARNING: this straight forward mapping is not supposed to work but it works thanks to the mesh-improver. */
6054 /* the changed u,v range is not considered, the necessary order is differend and should be updated */
6055 surf[ss[1]].nn=surf[s].nn;
6056 for(j=0; j<surf[ss[1]].nn; j++) surf[ss[1]].nod[j]=surf[s].nod[j];
6057 }
6058
6059 /* search the line between sm 0 and 1 */
6060 /* reset sml */
6061 for(i=0; i<4; i++) sml[0][i]=sml[1][i]=0;
6062 for(i=0; i<surf[sm[0][0]].nl; i++)
6063 {
6064 for(j=0; j<surf[sm[0][1]].nl; j++)
6065 {
6066 if(surf[sm[0][0]].l[i]==surf[sm[0][1]].l[j])
6067 {
6068 sml[0][i]=1; /* mark the line as known */
6069 tcomon=surf[sm[0][0]].typ[i];
6070 lcomon=surf[sm[0][0]].l[i];
6071 #if TEST
6072 if(tcomon=='l') printf(" line between sm 0:%s ,1:%s =%s\n", surf[sm[0][0]].name, surf[sm[0][1]].name,line[lcomon].name);
6073 if(tcomon=='c') printf(" lcmb between sm 0:%s ,1:%s =%s\n", surf[sm[0][0]].name, surf[sm[0][1]].name,lcmb[lcomon].name);
6074 #endif
6075 }
6076 }
6077 }
6078
6079 /* find the outer lines lm2 */
6080
6081 /* mark all surf-lines which are identical to lm */
6082 for(i=0; i<4; i++) for(j=0; j<2; j++) for(k=0; k<2; k++) for(n=0; n<2; n++)
6083 if((surf[sm[0][j]].l[i]==lm[k][n])&&(surf[sm[0][j]].typ[i]==tm[k][n])) sml[j][i]=1;
6084
6085 /* mark all surf-lines which are identical to lcomon */
6086 for(i=0; i<4; i++) for(j=0; j<2; j++)
6087 if((surf[sm[0][j]].l[i]==lcomon)&&(surf[sm[0][j]].typ[i]==tcomon)) sml[j][i]=1;
6088
6089 /* look which lines are unmarked on each 1st surf relating to the 5sided surfs */
6090 for(i=0; i<4; i++) if(sml[0][i]==0) { lm2[0]=surf[sm[0][0]].l[i]; tm2[0]=surf[sm[0][0]].typ[i]; }
6091 for(i=0; i<4; i++) if(sml[1][i]==0) { lm2[1]=surf[sm[0][1]].l[i]; tm2[1]=surf[sm[0][1]].typ[i]; }
6092
6093 #if TEST
6094 if(tm2[0]=='c') printf(" lm20:%s \n", lcmb[lm2[0]].name);
6095 else printf(" lm20:%s \n", line[lm2[0]].name);
6096 if(tm2[1]=='c') printf(" lm21:%s \n", lcmb[lm2[1]].name);
6097 else printf(" lm21:%s \n", line[lm2[1]].name);
6098 #endif
6099
6100 /* replace this surfs sm by a new one ss and map the nodes into it */
6101 clin[0]=cs[0];
6102 ctyp[0]='c';
6103 clin[1]=lm2[0];
6104 ctyp[1]=tm2[0];
6105 clin[2]=cs[1];
6106 ctyp[2]='c';
6107 clin[3]=lm2[1];
6108 ctyp[3]=tm2[1];
6109 for(j=0; j<6; j++) cori[j]='+';
6110 #if TEST
6111 for(j=0; j<4; j++)
6112 {
6113 if(ctyp[j]=='l')printf("clin[%d]:%s ctyp:%c cori:%c\n", j, line[clin[j]].name,ctyp[j],cori[j]);
6114 else if(ctyp[j]=='c')printf("clin[%d]:%s ctyp:%c cori:%c\n", j, lcmb[clin[j]].name,ctyp[j],cori[j]);
6115 else printf("typ:%c not known\n", ctyp[j]);
6116 }
6117 #endif
6118 getNewName( name, "s" );
6119 ss[5]= surface_i( name, surf[sm[0][0]].ori, -1, 4, cori, clin, ctyp );
6120 if(ss[5]<0) { printf("ERROR: surf could not be created\n"); return(-1); }
6121 setr( 0, "s", ss[5] );
6122 pre_seta(specialset->zap, "s", name);
6123
6124 /* map the nodes of the master-surfs into the slave-surf */
6125 /* determine the div of the surf */
6126 k=surf[sm[0][0]].l[0];
6127 umax0=0;
6128 if( surf[sm[0][0]].typ[0]=='l' ) umax0=line[k].div;
6129 else for( l=0; l<lcmb[k].nl; l++ ) umax0+=line[lcmb[k].l[l]].div;
6130 k=surf[sm[0][1]].l[0];
6131 umax1=0;
6132 if( surf[sm[0][1]].typ[0]=='l' ) umax1=line[k].div;
6133 else for( l=0; l<lcmb[k].nl; l++ ) umax1+=line[lcmb[k].l[l]].div;
6134
6135 k=surf[sm[0][0]].l[3];
6136 vmax0=0;
6137 if( surf[sm[0][0]].typ[3]=='l' ) vmax0=line[k].div;
6138 else for( l=0; l<lcmb[k].nl; l++ ) vmax0+=line[lcmb[k].l[l]].div;
6139 k=surf[sm[0][1]].l[3];
6140 vmax1=0;
6141 if( surf[sm[0][1]].typ[3]=='l' ) vmax1=line[k].div;
6142 else for( l=0; l<lcmb[k].nl; l++ ) vmax1+=line[lcmb[k].l[l]].div;
6143
6144 /* allocate space for the nodes of the slave-surf, for convenience it is allocated too big */
6145 if((surf[ss[5]].nod=(int *)realloc((int *)surf[ss[5]].nod,((umax0+umax1)*(vmax0+vmax1)+1)*sizeof(int)))==NULL)
6146 errMsg(" ERROR: realloc failure\n");
6147
6148 /* running-number of slave-surf-nodes */
6149 n=0;
6150
6151 /* store the nodes of the master sm[0][1] into nod[u][v] */
6152 if((sn = (int **)malloc((umax1+1)*sizeof(int *))) == NULL )
6153 errMsg(" ERROR: malloc failed in bodyFrom7Surfs()\n");
6154 for(k=0; k<(umax1+1); k++)
6155 {
6156 if((sn[k] = (int *)malloc((vmax1+1)*sizeof(int))) == NULL )
6157 errMsg(" ERROR: malloc failed in bodyFrom7Surfs()\n");
6158 }
6159 j=0; for (u=1; u<umax1; u++)
6160 {
6161 for (v=1; v<vmax1; v++)
6162 {
6163 sn[u][v]=surf[sm[0][1]].nod[j];
6164 j++;
6165 }
6166 }
6167 #if TEST
6168 printf("umax0:%d vmax0:%d umax1:%d vmax1:%d\n", umax0, vmax0, umax1, vmax1);
6169 printf("sm[0][1]:%s v:lm2[1]:%d u:lm[0][1]:%d\n", surf[sm[0][1]].name, lm2[1], lm[0][1] );
6170 for (v=0; v<4; v++) printf("surf_l[%d]:%d\n",v,surf[sm[0][1]].l[v]);
6171 #endif
6172 if((surf[sm[0][1]].l[0]==lm2[1])&&(surf[sm[0][1]].l[3]==lm[0][1]))
6173 {
6174 for (v=1; v<vmax1; v++)
6175 {
6176 for (u=1; u<umax1; u++)
6177 {
6178 surf[ss[5]].nod[n]=sn[u][v];
6179 n++;
6180 }
6181 }
6182 }
6183 else if((surf[sm[0][1]].l[2]==lm2[1])&&(surf[sm[0][1]].l[1]==lm[0][1]))
6184 {
6185 for (v=vmax1-1; v>0; v--)
6186 {
6187 for (u=umax1-1; u>0; u--)
6188 {
6189 surf[ss[5]].nod[n]=sn[u][v];
6190 n++;
6191 }
6192 }
6193 }
6194 else if((surf[sm[0][1]].l[3]==lm2[1])&&(surf[sm[0][1]].l[2]==lm[0][1]))
6195 {
6196 for (u=1; u<umax1; u++)
6197 {
6198 for (v=vmax1-1; v>0; v--)
6199 {
6200 surf[ss[5]].nod[n]=sn[u][v];
6201 n++;
6202 }
6203 }
6204 }
6205 else if((surf[sm[0][1]].l[1]==lm2[1])&&(surf[sm[0][1]].l[0]==lm[0][1]))
6206 {
6207 for (u=umax1-1; u>0; u--)
6208 {
6209 for (v=1; v<vmax1; v++)
6210 {
6211 surf[ss[5]].nod[n]=sn[u][v];
6212 n++;
6213 }
6214 }
6215 }
6216 else if((surf[sm[0][1]].l[0]==lm2[1])&&(surf[sm[0][1]].l[1]==lm[0][1]))
6217 {
6218 for (v=1; v<vmax1; v++)
6219 {
6220 for (u=umax1-1; u>0; u--)
6221 {
6222 surf[ss[5]].nod[n]=sn[u][v];
6223 n++;
6224 }
6225 }
6226 }
6227 else if((surf[sm[0][1]].l[2]==lm2[1])&&(surf[sm[0][1]].l[3]==lm[0][1]))
6228 {
6229 for (v=vmax1-1; v>0; v--)
6230 {
6231 for (u=1; u<umax1; u++)
6232 {
6233 surf[ss[5]].nod[n]=sn[u][v];
6234 n++;
6235 }
6236 }
6237 }
6238 else if((surf[sm[0][1]].l[3]==lm2[1])&&(surf[sm[0][1]].l[0]==lm[0][1]))
6239 {
6240 for (u=1; u<umax1; u++)
6241 {
6242 for (v=1; v<vmax1; v++)
6243 {
6244 surf[ss[5]].nod[n]=sn[u][v];
6245 n++;
6246 }
6247 }
6248 }
6249 else if((surf[sm[0][1]].l[1]==lm2[1])&&(surf[sm[0][1]].l[2]==lm[0][1]))
6250 {
6251 for (u=umax1-1; u>0; u--)
6252 {
6253 for (v=vmax1-1; v>0; v--)
6254 {
6255 surf[ss[5]].nod[n]=sn[u][v];
6256 n++;
6257 }
6258 }
6259 }
6260 else
6261 {
6262 errMsg("BUG: found no surface orientation for surf:%s\n", surf[sm[0][1]].name );
6263 exit(-1);
6264 }
6265 for(k=0; k<(umax1+1); k++) free(sn[k]);
6266 free(sn);
6267
6268 /* add the nodes of lcomon */
6269 /* search the index of the point between lm[0][0] and lm[0][1] */
6270 if(( tm[0][0]=='l')&&( tm[0][1]=='l'))
6271 {
6272 if( line[lm[0][0]].p1==line[lm[0][1]].p1) ps=line[lm[0][0]].p1;
6273 else if( line[lm[0][0]].p1==line[lm[0][1]].p2) ps=line[lm[0][0]].p1;
6274 else if( line[lm[0][0]].p2==line[lm[0][1]].p2) ps=line[lm[0][0]].p2;
6275 else if( line[lm[0][0]].p2==line[lm[0][1]].p1) ps=line[lm[0][0]].p2;
6276 }
6277 else if(( tm[0][0]=='l')&&( tm[0][1]=='c'))
6278 {
6279 if( line[lm[0][0]].p1==lcmb[lm[0][1]].p1) ps=line[lm[0][0]].p1;
6280 else if( line[lm[0][0]].p1==lcmb[lm[0][1]].p2) ps=line[lm[0][0]].p1;
6281 else if( line[lm[0][0]].p2==lcmb[lm[0][1]].p2) ps=line[lm[0][0]].p2;
6282 else if( line[lm[0][0]].p2==lcmb[lm[0][1]].p1) ps=line[lm[0][0]].p2;
6283 }
6284 else if(( tm[0][0]=='c')&&( tm[0][1]=='l'))
6285 {
6286 if( lcmb[lm[0][0]].p1==line[lm[0][1]].p1) ps=lcmb[lm[0][0]].p1;
6287 else if( lcmb[lm[0][0]].p1==line[lm[0][1]].p2) ps=lcmb[lm[0][0]].p1;
6288 else if( lcmb[lm[0][0]].p2==line[lm[0][1]].p2) ps=lcmb[lm[0][0]].p2;
6289 else if( lcmb[lm[0][0]].p2==line[lm[0][1]].p1) ps=lcmb[lm[0][0]].p2;
6290 }
6291 else if(( tm[0][0]=='c')&&( tm[0][1]=='c'))
6292 {
6293 if( lcmb[lm[0][0]].p1==lcmb[lm[0][1]].p1) ps=lcmb[lm[0][0]].p1;
6294 else if( lcmb[lm[0][0]].p1==lcmb[lm[0][1]].p2) ps=lcmb[lm[0][0]].p1;
6295 else if( lcmb[lm[0][0]].p2==lcmb[lm[0][1]].p2) ps=lcmb[lm[0][0]].p2;
6296 else if( lcmb[lm[0][0]].p2==lcmb[lm[0][1]].p1) ps=lcmb[lm[0][0]].p2;
6297 }
6298 if(ps<0) { printf("ERROR: ps:%d can not be determined\n", ps); exit(-1); }
6299
6300 /* look how the line is oriented relative to ps */
6301 if(tcomon=='l')
6302 {
6303 if(ps==line[lcomon].p1)
6304 {
6305 for (v=0; v<line[lcomon].div-1; v++)
6306 {
6307 surf[ss[5]].nod[n]=line[lcomon].nod[v];
6308 n++;
6309 }
6310 }
6311 else
6312 {
6313 for (v=line[lcomon].div-2; v>-1; v--)
6314 {
6315 surf[ss[5]].nod[n]=line[lcomon].nod[v];
6316 n++;
6317 }
6318 }
6319 }
6320 else /* tcomon=='c' */
6321 {
6322 if(ps==lcmb[lcomon].p1)
6323 {
6324 for( l=0; l<lcmb[lcomon].nl; l++ )
6325 {
6326 if(lcmb[lcomon].o[l]=='+')
6327 {
6328 for (v=0; v<line[lcmb[lcomon].l[l]].div-1; v++)
6329 {
6330 surf[ss[5]].nod[n]=line[lcmb[lcomon].l[l]].nod[v];
6331 n++;
6332 }
6333 /* add the node at the end of the line */
6334 surf[ss[5]].nod[n]=point[line[lcmb[lcomon].l[l]].p2].nod[0];
6335 n++;
6336 }
6337 else
6338 {
6339 for (v=line[lcmb[lcomon].l[l]].div-2; v>-1; v--)
6340 {
6341 surf[ss[5]].nod[n]=line[lcmb[lcomon].l[l]].nod[v];
6342 n++;
6343 }
6344 /* add the node at the end of the line */
6345 surf[ss[5]].nod[n]=point[line[lcmb[lcomon].l[l]].p1].nod[0];
6346 n++;
6347 }
6348 }
6349 }
6350 else
6351 {
6352 for( l=0; l<lcmb[lcomon].nl; l++ )
6353 {
6354 if(lcmb[lcomon].o[l]=='-')
6355 {
6356 for (v=0; v<line[lcmb[lcomon].l[l]].div-1; v++)
6357 {
6358 surf[ss[5]].nod[n]=line[lcmb[lcomon].l[l]].nod[v];
6359 n++;
6360 }
6361 /* add the node at the end of the line */
6362 surf[ss[5]].nod[n]=point[line[lcmb[lcomon].l[l]].p1].nod[0];
6363 n++;
6364 }
6365 else
6366 {
6367 for (v=line[lcmb[lcomon].l[l]].div-2; v>-1; v--)
6368 {
6369 surf[ss[5]].nod[n]=line[lcmb[lcomon].l[l]].nod[v];
6370 n++;
6371 }
6372 /* add the node at the end of the line */
6373 surf[ss[5]].nod[n]=point[line[lcmb[lcomon].l[l]].p2].nod[0];
6374 n++;
6375 }
6376 }
6377 }
6378 n--;
6379 }
6380
6381
6382 /* store the nodes of the master sm[0][0] into nod[u][v] */
6383 if((sn = (int **)malloc((umax0+1)*sizeof(int *))) == NULL )
6384 errMsg(" ERROR: malloc failed in bodyFrom7Surfs()\n");
6385 for(k=0; k<(umax0+1); k++)
6386 {
6387 if((sn[k] = (int *)malloc((vmax0+1)*sizeof(int))) == NULL )
6388 errMsg(" ERROR: malloc failed in bodyFrom7Surfs()\n");
6389 }
6390 j=0; for (u=1; u<umax0; u++)
6391 {
6392 for (v=1; v<vmax0; v++)
6393 {
6394 sn[u][v]=surf[sm[0][0]].nod[j];
6395 j++;
6396 }
6397 }
6398 if((surf[sm[0][0]].l[0]==lm2[0])&&(surf[sm[0][0]].l[3]==lm[0][0]))
6399 {
6400 for (v=vmax0-1; v>0; v--)
6401 {
6402 for (u=1; u<umax0; u++)
6403 {
6404 surf[ss[5]].nod[n]=sn[u][v];
6405 n++;
6406 }
6407 }
6408 }
6409 else if((surf[sm[0][0]].l[2]==lm2[0])&&(surf[sm[0][0]].l[1]==lm[0][0]))
6410 {
6411 for (v=1; v<vmax0; v++)
6412 {
6413 for (u=umax0-1; u>0; u--)
6414 {
6415 surf[ss[5]].nod[n]=sn[u][v];
6416 n++;
6417 }
6418 }
6419 }
6420 else if((surf[sm[0][0]].l[3]==lm2[0])&&(surf[sm[0][0]].l[2]==lm[0][0]))
6421 {
6422 for (u=umax0-1; u>0; u--)
6423 {
6424 for (v=vmax0-1; v>0; v--)
6425 {
6426 surf[ss[5]].nod[n]=sn[u][v];
6427 n++;
6428 }
6429 }
6430 }
6431 else if((surf[sm[0][0]].l[1]==lm2[0])&&(surf[sm[0][0]].l[0]==lm[0][0]))
6432 {
6433 for (u=1; u<umax0; u++)
6434 {
6435 for (v=1; v<vmax0; v++)
6436 {
6437 surf[ss[5]].nod[n]=sn[u][v];
6438 n++;
6439 }
6440 }
6441 }
6442 else if((surf[sm[0][0]].l[0]==lm2[0])&&(surf[sm[0][0]].l[1]==lm[0][0]))
6443 {
6444 for (v=vmax0-1; v>0; v--)
6445 {
6446 for (u=umax0-1; u>0; u--)
6447 {
6448 surf[ss[5]].nod[n]=sn[u][v];
6449 n++;
6450 }
6451 }
6452 }
6453 else if((surf[sm[0][0]].l[2]==lm2[0])&&(surf[sm[0][0]].l[3]==lm[0][0]))
6454 {
6455 for (v=1; v<vmax0; v++)
6456 {
6457 for (u=1; u<umax0; u++)
6458 {
6459 surf[ss[5]].nod[n]=sn[u][v];
6460 n++;
6461 }
6462 }
6463 }
6464 else if((surf[sm[0][0]].l[3]==lm2[0])&&(surf[sm[0][0]].l[0]==lm[0][0]))
6465 {
6466 for (u=umax0-1; u>0; u--)
6467 {
6468 for (v=1; v<vmax0; v++)
6469 {
6470 surf[ss[5]].nod[n]=sn[u][v];
6471 n++;
6472 }
6473 }
6474 }
6475 else if((surf[sm[0][0]].l[1]==lm2[0])&&(surf[sm[0][0]].l[2]==lm[0][0]))
6476 {
6477 for (u=1; u<umax0; u++)
6478 {
6479 for (v=vmax0-1; v>0; v--)
6480 {
6481 surf[ss[5]].nod[n]=sn[u][v];
6482 n++;
6483 }
6484 }
6485 }
6486 else
6487 {
6488 errMsg("BUG: found no surface orientation\n");
6489 exit(-1);
6490 }
6491 for(k=0; k<(umax0+1); k++) free(sn[k]);
6492 free(sn);
6493
6494 /* create a new body with this surfs */
6495 j=2; for(i=2; i<7; i++)
6496 {
6497 if((body[*b].s[i]!=sm[0][0])&&(body[*b].s[i]!=sm[0][1])) { ss[j]=body[*b].s[i]; j++; }
6498 }
6499 #if TEST
6500 for(i=0; i<6; i++)
6501 {
6502 printf("body: s:%s c:%c\n", surf[ss[i]].name, cori[i]);
6503 }
6504 #endif
6505 getNewName( name, "b" );
6506 bs= gbod_i( name, -1, 6, cori, ss );
6507 if(bs<0) { printf("ERROR: body could not be created\n"); return(-1); }
6508 setr(0,"b",bs);
6509 pre_seta(specialset->zap, "b", name);
6510 body[bs].etyp=body[*b].etyp;
6511 body[bs].eattr=body[*b].eattr;
6512 *b=bs;
6513 return(1);
6514 }
6515
6516
6517 /* suche die Eckpunkte der surfaces, setzt einen orientierten body voraus. */
6518 /* beruecksichtige dabei die orientierung der linien oder lcmbs */
6519 /* so das die punktefolge der linienfolge entspricht */
6520 /* return -1 if failed, 1 if successfull */
generateBodyCornerPoints(int b_indx,int * bcp,int * srefp)6521 int generateBodyCornerPoints( int b_indx, int *bcp, int *srefp)
6522 {
6523 int i, j=0, s, sl, cl, err=0;
6524 int **scp; /* corner points of the surfs */
6525
6526 if( (scp=(int **)malloc((body[b_indx].ns+1)*sizeof(int *) ) )==NULL)
6527 { printf(" ERROR: malloc failure in generateBodyCornerPoints()\n"); return(-1); }
6528 for(i=0; i<body[b_indx].ns; i++)
6529 {
6530 if( (scp[i]=(int *)malloc((surf[body[b_indx].s[i]].nl+1)*sizeof(int) ) )==NULL)
6531 { printf(" ERROR: malloc failure in generateBodyCornerPoints()\n"); return(-1); }
6532 }
6533
6534 for (i=0; i<body[b_indx].ns; i++)
6535 {
6536 s=body[b_indx].s[i];
6537 /* suche den ersten punkt der ersten linie oder lcmb der i-ten surf */
6538 sl=surf[s].l[0];
6539 if (surf[s].typ[0]=='c')
6540 {
6541 cl=lcmb[sl].nl-1;
6542 if (surf[s].o[0]=='-')
6543 {
6544 if(lcmb[sl].o[cl]=='+') scp[i][0]=line[lcmb[sl].l[cl]].p2;
6545 else scp[i][0]=line[lcmb[sl].l[cl]].p1;
6546 }
6547 else
6548 {
6549 if(lcmb[sl].o[0]=='+') scp[i][0]=line[lcmb[sl].l[0]].p1;
6550 else scp[i][0]=line[lcmb[sl].l[0]].p2;
6551 }
6552 }
6553 else if (surf[s].typ[0]=='l')
6554 {
6555 if (surf[s].o[0]=='-')
6556 {
6557 scp[i][0]=line[surf[s].l[0]].p2;
6558 }
6559 else
6560 {
6561 scp[i][0]=line[surf[s].l[0]].p1;
6562 }
6563 }
6564 else { errMsg (" ERROR: , surf.typ:%1c not known\n", surf[s].typ[j]); exit(-1);}
6565
6566 /* suche den anfangspunkt aller weiteren linien oder lcmbs der surf */
6567 for (j=1; j<surf[s].nl; j++)
6568 {
6569 sl=surf[s].l[j];
6570 if (surf[s].typ[j]=='c')
6571 {
6572 cl=lcmb[sl].nl-1;
6573 if (surf[s].o[j]=='-')
6574 {
6575 if(lcmb[sl].o[cl]=='+') scp[i][j]=line[lcmb[sl].l[cl]].p2;
6576 else scp[i][j]=line[lcmb[sl].l[cl]].p1;
6577 }
6578 else
6579 {
6580 if(lcmb[sl].o[0]=='+') scp[i][j]=line[lcmb[sl].l[0]].p1;
6581 else scp[i][j]=line[lcmb[sl].l[0]].p2;
6582 }
6583 }
6584 else if (surf[s].typ[j]=='l')
6585 {
6586 if (surf[s].o[j]=='-')
6587 {
6588 scp[i][j]=line[surf[s].l[j]].p2;
6589 }
6590 else
6591 {
6592 scp[i][j]=line[surf[s].l[j]].p1;
6593 }
6594 }
6595 else { errMsg (" ERROR: surf.typ:%1c not known\n", surf[s].typ[j]); exit(-1);}
6596 }
6597 #if TEST1
6598 printf ("Edge-points of Surf:%s ", surf[s].name );
6599 for (j=0; j<surf[s].nl; j++)
6600 printf (" scp[%d][%d]=%d",i,j, scp[i][j]);
6601 for (j=0; j<surf[s].nl; j++)
6602 printf (" %s", point[scp[i][j]].name);
6603 printf ("\n");
6604 #endif
6605 }
6606
6607 /* die surfs des 6-seitigen bodies muessen 4 kanten haben! */
6608 for(s=0; s<body[b_indx].ns; s++)
6609 {
6610 j=body[b_indx].s[s];
6611 if (surf[j].nl!=4)
6612 {
6613 printf(" ERROR: Surf has no %d edges (has:%d)\n", MAX_EDGES_PER_SURF, surf[j].nl );
6614 err=-1;
6615 goto noEdges;
6616 }
6617 }
6618
6619 /* bestimmung der body-edges */
6620
6621 /* bcp 0-3 werden durch die Mastersurf (0) festgelegt (orientabhaengig) */
6622 if ( body[b_indx].o[0]=='+')
6623 {
6624 bcp[0]=scp[0][3];
6625 bcp[1]=scp[0][2];
6626 bcp[2]=scp[0][1];
6627 bcp[3]=scp[0][0];
6628 }
6629 else if (body[b_indx].o[0]=='-')
6630 {
6631 bcp[0]=scp[0][2];
6632 bcp[1]=scp[0][3];
6633 bcp[2]=scp[0][0];
6634 bcp[3]=scp[0][1];
6635 }
6636 else
6637 {
6638 errMsg (" ERROR: surface-orientation not known.\n");
6639 exit(-1);
6640 }
6641
6642 /* bcp 4-5 werden durch die surf (2) festgelegt (orientabhaengig) */
6643 /* suche den mit bcp(0) verbundenen punkt (Verknuepfungspunkt) */
6644 for(j=0; j<MAX_EDGES_PER_SURF; j++)
6645 {
6646 if (scp[2][j]==bcp[0])
6647 {
6648 if ( body[b_indx].o[2]=='+')
6649 {
6650 if (j==0)
6651 {
6652 bcp[5]=scp[2][2];
6653 bcp[4]=scp[2][3];
6654 }
6655 else if (j==1)
6656 {
6657 bcp[5]=scp[2][3];
6658 bcp[4]=scp[2][0];
6659 }
6660 else if (j==2)
6661 {
6662 bcp[5]=scp[2][0];
6663 bcp[4]=scp[2][1];
6664 }
6665 else if (j==3)
6666 {
6667 bcp[5]=scp[2][1];
6668 bcp[4]=scp[2][2];
6669 }
6670 else
6671 {
6672 errMsg (" ERROR: edge not known.\n");
6673 exit(-1);
6674 }
6675 }
6676 else if (body[b_indx].o[2]=='-')
6677 {
6678 if (j==0)
6679 {
6680 bcp[5]=scp[2][2];
6681 bcp[4]=scp[2][1];
6682 }
6683 else if (j==1)
6684 {
6685 bcp[5]=scp[2][3];
6686 bcp[4]=scp[2][2];
6687 }
6688 else if (j==2)
6689 {
6690 bcp[5]=scp[2][0];
6691 bcp[4]=scp[2][3];
6692 }
6693 else if (j==3)
6694 {
6695 bcp[5]=scp[2][1];
6696 bcp[4]=scp[2][0];
6697 }
6698 else
6699 {
6700 errMsg (" ERROR: edge not known.\n");
6701 exit(-1);
6702 }
6703 }
6704 else
6705 {
6706 errMsg (" ERROR: surface-orientation not known.\n");
6707 exit(-1);
6708 }
6709 }
6710 }
6711
6712 /* bcp 6-7 werden durch die surf (4) festgelegt (orientabhaengig) */
6713 /* suche den mit bcp(3) verbundenen punkt (Verknuepfungspunkt) */
6714 for(j=0; j<MAX_EDGES_PER_SURF; j++)
6715 {
6716 if (scp[4][j]==bcp[3])
6717 {
6718 if ( body[b_indx].o[4]=='-')
6719 {
6720 if (j==0)
6721 {
6722 bcp[6]=scp[4][2];
6723 bcp[7]=scp[4][3];
6724 }
6725 else if (j==1)
6726 {
6727 bcp[6]=scp[4][3];
6728 bcp[7]=scp[4][0];
6729 }
6730 else if (j==2)
6731 {
6732 bcp[6]=scp[4][0];
6733 bcp[7]=scp[4][1];
6734 }
6735 else if (j==3)
6736 {
6737 bcp[6]=scp[4][1];
6738 bcp[7]=scp[4][2];
6739 }
6740 else
6741 {
6742 errMsg (" ERROR: edge not known.\n");
6743 exit(-1);
6744 }
6745 }
6746 else if (body[b_indx].o[4]=='+')
6747 {
6748 if (j==0)
6749 {
6750 bcp[6]=scp[4][2];
6751 bcp[7]=scp[4][1];
6752 }
6753 else if (j==1)
6754 {
6755 bcp[6]=scp[4][3];
6756 bcp[7]=scp[4][2];
6757 }
6758 else if (j==2)
6759 {
6760 bcp[6]=scp[4][0];
6761 bcp[7]=scp[4][3];
6762 }
6763 else if (j==3)
6764 {
6765 bcp[6]=scp[4][1];
6766 bcp[7]=scp[4][0];
6767 }
6768 else
6769 {
6770 errMsg (" ERROR: edge not known.\n");
6771 exit(-1);
6772 }
6773 }
6774 else
6775 {
6776 errMsg (" ERROR: surface-orientation not known.\n");
6777 exit(-1);
6778 }
6779 }
6780 }
6781
6782 /* bestimmung der Referenzpunkte der Surfaces */
6783 /* srefp[0]=cp-index der Bodysurf:0 der mit bcp[0] zussammenfaellt. */
6784 /* srefp[1]=cp-index der Bodysurf:1 der mit bcp[7] zussammenfaellt. */
6785 /* srefp[2]=cp-index der Bodysurf:2 der mit bcp[0] zussammenfaellt. */
6786 /* srefp[3]=cp-index der Bodysurf:3 der mit bcp[0] zussammenfaellt. */
6787 /* srefp[4]=cp-index der Bodysurf:4 der mit bcp[3] zussammenfaellt. */
6788 /* srefp[5]=cp-index der Bodysurf:5 der mit bcp[1] zussammenfaellt. */
6789 for(j=0; j<MAX_EDGES_PER_SURF; j++) srefp[j]=-1;
6790 for(j=0; j<MAX_EDGES_PER_SURF; j++)
6791 {
6792 if (scp[0][j]==bcp[0]) srefp[0]=j;
6793 if (scp[2][j]==bcp[0]) srefp[2]=j;
6794 if (scp[3][j]==bcp[0]) srefp[3]=j;
6795 if (scp[4][j]==bcp[3]) srefp[4]=j;
6796 if (scp[5][j]==bcp[1]) srefp[5]=j;
6797 }
6798 /* Bodysurf 1 ist ein sonderfall. Diese Surface kann zu einer Linie oder einem Punkt */
6799 /* kollabiert sein. In diesem Fall muessen zwei aufeinander folgende Punkte abgeprueft*/
6800 /* werden (diese bilden eine Kante). Die gesuchte Kante bildet die "u"-Achse und */
6801 /* laeuft fuer die + orientierte surface von bcp7 zu bcp4. */
6802 srefp[1]=-1;
6803 if (body[b_indx].o[1]=='+')
6804 {
6805 if ((scp[1][0]==bcp[7])&&(scp[1][1]==bcp[4])) srefp[1]=0;
6806 if ((scp[1][1]==bcp[7])&&(scp[1][2]==bcp[4])) srefp[1]=1;
6807 if ((scp[1][2]==bcp[7])&&(scp[1][3]==bcp[4])) srefp[1]=2;
6808 if ((scp[1][3]==bcp[7])&&(scp[1][0]==bcp[4])) srefp[1]=3;
6809 }
6810 else /* surf is - oriented */
6811 {
6812 if ((scp[1][0]==bcp[7])&&(scp[1][1]==bcp[6])) srefp[1]=0;
6813 if ((scp[1][1]==bcp[7])&&(scp[1][2]==bcp[6])) srefp[1]=1;
6814 if ((scp[1][2]==bcp[7])&&(scp[1][3]==bcp[6])) srefp[1]=2;
6815 if ((scp[1][3]==bcp[7])&&(scp[1][0]==bcp[6])) srefp[1]=3;
6816 }
6817 for(j=0; j<6;j++) if(srefp[j]<0)
6818 {
6819 errMsg(" ERROR: edge:%d not known:%d, body:%s\n", j, srefp[j], body[b_indx].name );
6820 err=-1;
6821 goto noEdges;
6822 }
6823
6824 #if TEST1
6825 for(j=0; j<6;j++)
6826 printf ("surf[%d]:%s refpnt:%s edge:%d\n",j, surf[ body[b_indx].s[j] ].name, point[ (scp[j][srefp[j]]) ].name, srefp[j]);
6827 #endif
6828 err=1;
6829 for(i=0; i<body[b_indx].ns; i++) free(scp[i]);
6830 free(scp);
6831 noEdges:;
6832 return(err);
6833 }
6834
6835
6836 int glob_bod=0;
thread_genNodeFromBody(void * vargp)6837 void *thread_genNodeFromBody(void *vargp)
6838 {
6839 int i,j,k,n,s,bod, u,v,w, a,b=0,c;
6840 int setNr, nmax;
6841 int bcp[MAX_CORNERS_PER_BODY]; /* corner points of the body */
6842 int noBodyMesh=0;
6843 int *mapbody;
6844 int umax,vmax,wmax, b_indx;
6845 int amax,bmax,cmax, offs_sa1, offs_sa2, div_sa1, div_sa2;
6846 int en[26];
6847 int *n_uvw;
6848 int *n_abc;
6849
6850 /* variables for the mesh-improver */
6851 int nj, *n_indx=NULL, *n_ori=NULL, **e_nod=NULL, *n_type=NULL, **n_edge=NULL, **s_div=NULL;
6852 double **n_coord=NULL;
6853
6854 /* and for cfd-mesh */
6855 int ii, jj;
6856 char surFlag;
6857 int bcp2[MAX_CORNERS_PER_BODY]; /* corner points of the corresponding body */
6858 int bcp3[MAX_CORNERS_PER_BODY]; /* corner points of the corresponding body */
6859 int div_lu[6][4];
6860 int imax, jmax, kmax;
6861 int iislave=0;
6862 int srefp[6]; /* Reference-point of the Surface to the body */
6863 int unbalance[MAX_SURFS_PER_BODY];
6864
6865 typedef struct {
6866 int vargp[6];
6867 int *mapbody;
6868 } Threadargs;
6869 Threadargs *param;
6870
6871 param=(Threadargs *)vargp;
6872 setNr=param->vargp[0];
6873 mapbody=param->mapbody;
6874
6875 /* evaluate the bodies */
6876 while(1)
6877 {
6878 sem_wait(&sem_g);
6879 bod=glob_bod++;
6880 sem_post(&sem_g);
6881 if(bod>=param->vargp[1]) break;
6882 if(mapbody[bod]>-1) b_indx= mapbody[bod];
6883 //if(mapbody[bod]>-1) continue;
6884 else b_indx=set[setNr].body[bod];
6885
6886 if(body[b_indx].fail==1) continue;
6887 body[b_indx].fail=1;
6888 if( body[b_indx].name == (char *)NULL ) continue;
6889
6890
6891 /* check if all surfs defining the body were successfully meshed before. */
6892 /* check if all surfs defining the body use a suited element type and attribute. */
6893 for(i=0; i<body[b_indx].ns; i++)
6894 {
6895 if(surf[body[b_indx].s[i]].fail==1)
6896 { printf("ERROR: surf:%s of body:%s not meshed\n",surf[body[b_indx].s[i]].name,body[b_indx].name); goto badBody; }
6897 if(surf[body[b_indx].s[i]].eattr==-1)
6898 { printf("ERROR: surf:%s of body:%s holds unsuited elements of attr:%d\n",surf[body[b_indx].s[i]].name,body[b_indx].name, surf[body[b_indx].s[i]].eattr); goto badBody; }
6899 }
6900
6901 /* suche die Eckpunkte der surfaces, setzt einen orientierten body voraus. */
6902 /* so das die punktefolge der linienfolge entspricht */
6903 if( generateBodyCornerPoints( b_indx, bcp, srefp) == -1) goto badBody;
6904
6905 #if TEST1
6906 /* liste die gefundenen Eckpunkte des bodies */
6907 printf ("Edgepoints of Body:%s ", body[b_indx].name );
6908 for (j=0; j<MAX_CORNERS_PER_BODY; j++)
6909 printf (" %s", point[bcp[j]].name);
6910 printf ("\n");
6911 #endif
6912
6913 /* Bodytopologie: bestimme die parametrischen Kantenlaengen des bodies */
6914 /* Der Nullpunkt liegt im Schnittpunkt von surf 0 2 3 (surfs starten mit 0) */
6915 /* Die u-Achse liegt in der schnittlinie von 2 3 */
6916 /* Die v-Achse liegt in der schnittlinie von 0 2 */
6917 /* Die w-Achse liegt in der schnittlinie von 0 3 */
6918
6919 /* Bestimme die divisions der 6 bodyflaechen zur erkennung von unbalance und */
6920 /* bestimme die parametrischen Kantenlaengen des bodies umax, vmax, wmax mit s2 und s3 */
6921 /* fuer den fall das kein unbalance erkannt wurde */
6922
6923 n=0;
6924 for(j=0; j<MAX_SURFS_PER_BODY;j++)
6925 {
6926 body[b_indx].unbalance[j]= getSurfDivs( b_indx, j, &body[b_indx].div_l[j][0] );
6927 if (body[b_indx].unbalance[j]==-1) goto badBody;
6928 n+=body[b_indx].unbalance[j];
6929 }
6930 if(n==2) body[b_indx].typ=1;
6931 else if(n==0) body[b_indx].typ=0;
6932 else body[b_indx].typ=-1;
6933
6934 /* unbalanced body-surfs */
6935 if(body[b_indx].typ==1)
6936 {
6937 /* only two surfs must be unbalanced and must be opposite */
6938 if( evalBody2( b_indx )==-1) goto badBody;
6939 }
6940 /* body-surfs have balanced edges */
6941 else if (body[b_indx].typ==0)
6942 {
6943 if( evalBody( b_indx, srefp)==-1) goto badBody;
6944 body[b_indx].s_indx[0]=srefp[0];
6945 body[b_indx].s_indx[1]=srefp[1];
6946 body[b_indx].s_indx[2]=srefp[2];
6947 body[b_indx].s_indx[3]=srefp[3];
6948 body[b_indx].s_indx[4]=srefp[4];
6949 body[b_indx].s_indx[5]=srefp[5];
6950 }
6951 else
6952 {
6953 /* wrong number of surfs are not balanced */
6954 /* body is not meshable */
6955 goto badBody;
6956 }
6957
6958 if(body[b_indx].typ==1)
6959 {
6960 if( fillBody2( b_indx, &n_abc)==-1) body[b_indx].fail=1;
6961 }
6962 else
6963 {
6964 if( fillBody( b_indx, &n_uvw)==-1) body[b_indx].fail=1;
6965 }
6966 nmax=apre->nmax;
6967
6968 /******* generation of elements **********/
6969
6970 /* body with unbalanced body-surfs */
6971 if (body[b_indx].typ==1)
6972 {
6973 amax =body[b_indx].umax;
6974 bmax =body[b_indx].vmax;
6975 cmax =body[b_indx].wmax;
6976 offs_sa1 =body[b_indx].offs_sa1;
6977 offs_sa2 =body[b_indx].offs_sa2;
6978 div_sa1 =body[b_indx].div_sa1;
6979 div_sa2 =body[b_indx].div_sa2;
6980
6981 /* allocate memory for embeded elements */
6982 if((body[b_indx].elem=(int *)realloc((int *)body[b_indx].elem, (amax*bmax*cmax)*sizeof(int)) )==NULL)
6983 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n"
6984 , body[b_indx].name); return((void *)0); }
6985
6986 /* START of section mesh-improver, allocate memory for the mesh-improver */
6987 if((n_indx=(int *)realloc((int *)n_indx, (nmax+1)*sizeof(int)) )==NULL)
6988 { printf(" ERROR: n_indx realloc failure body:%s can not be meshed\n\n"
6989 , body[b_indx].name); return((void *)0); }
6990 if((n_ori=(int *)realloc((int *)n_ori, (amax*bmax*cmax)*sizeof(int)) )==NULL)
6991 { printf(" ERROR: n_ori realloc failure body:%s can not be meshed\n\n"
6992 , body[b_indx].name); return((void *)0); }
6993 if((e_nod=(int **)realloc((int **)e_nod, (amax*bmax*cmax)*sizeof(int *)) )==NULL)
6994 { printf(" ERROR: e_nod realloc failure body:%s can not be meshed\n\n"
6995 , body[b_indx].name); return((void *)0); }
6996 for (i=0; i<(amax*bmax*cmax); i++)
6997 if((e_nod[i]=(int *)malloc( (int)20*sizeof(int)) )==NULL)
6998 { printf(" ERROR: e_nod[i] malloc failure body:%s can not be meshed\n\n"
6999 , body[b_indx].name); return((void *)0); }
7000 if((n_edge=(int **)realloc((int **)n_edge, (int)MAX_SURFS_PER_BODY*sizeof(int *)) )==NULL)
7001 { printf(" ERROR: n_edge realloc failure body:%s can not be meshed\n\n"
7002 , body[b_indx].name); return((void *)0); }
7003 for (i=0; i<MAX_SURFS_PER_BODY; i++)
7004 if((n_edge[i]=(int *)malloc( (int)(amax*bmax*cmax)*sizeof(int)) )==NULL)
7005 { printf(" ERROR: n_edge[%d] malloc failure body:%s can not be meshed\n\n"
7006 , i, body[b_indx].name); return((void *)0); }
7007 if((s_div=(int **)realloc((int **)s_div, (int)MAX_SURFS_PER_BODY*sizeof(int *)) )==NULL)
7008 { printf(" ERROR: s_div realloc failure body:%s can not be meshed\n\n"
7009 , body[b_indx].name); return((void *)0); }
7010 for (i=0; i<MAX_SURFS_PER_BODY; i++)
7011 if((s_div[i]=(int *)malloc( (int)MAX_EDGES_PER_SURF*sizeof(int)) )==NULL)
7012 { printf(" ERROR: s_div[i] malloc failure body:%s can not be meshed\n\n"
7013 , body[b_indx].name); return((void *)0); }
7014 if((n_type=(int *)realloc((int *)n_type, (amax*bmax*cmax+1)*sizeof(int)) )==NULL)
7015 { printf(" ERROR: n_type realloc failure body:%s can not be meshed\n\n"
7016 , body[b_indx].name); return((void *)0); }
7017 if((n_coord=(double **)realloc((double **)n_coord, (int)(amax*bmax*cmax)*sizeof(double *)) )==NULL)
7018 { printf(" ERROR: n_coord realloc failure body:%s can not be meshed\n\n"
7019 , body[b_indx].name); return((void *)0); }
7020 for (i=0; i<(amax*bmax*cmax); i++)
7021 if((n_coord[i]=(double *)malloc( (int)3*sizeof(double)) )==NULL)
7022 { printf(" ERROR: n_coord[%d] malloc failure body:%s can not be meshed\n\n"
7023 , i, body[b_indx].name); return((void *)0); }
7024
7025 /* ini data for mesh-improver */
7026 j=0;
7027 for(i=0; i<=nmax; i++) n_indx[i]=-1; /* initialized as unused */
7028 for(i=0; i<(amax*bmax*cmax); i++) n_type[i]=0; /* initialized as bulk nodes */
7029 /* INTERRUPT of section mesh-improver */
7030
7031 k=0;
7032 if (body[b_indx].etyp==1)
7033 {
7034 for (c=0; c<cmax-1; c++)
7035 {
7036 for (a=0; a<amax-1; a++)
7037 {
7038 for (b=0; b<bmax-1; b++)
7039 {
7040 if ((a>=div_sa1)&&(b<offs_sa1)) goto noelem1a;
7041 if ((a>=div_sa2)&&(b>=bmax-1-offs_sa2)) goto noelem1a;
7042 en[0]=n_abc[(a )*bmax*cmax + b *cmax +c];
7043 en[1]=n_abc[(a+1)*bmax*cmax + b *cmax +c];
7044 en[2]=n_abc[(a+1)*bmax*cmax + (b+1) *cmax +c];
7045 en[3]=n_abc[(a )*bmax*cmax + (b+1) *cmax +c];
7046 en[4]=n_abc[(a )*bmax*cmax + b *cmax +(c+1)];
7047 en[5]=n_abc[(a+1)*bmax*cmax + b *cmax +(c+1)];
7048 en[6]=n_abc[(a+1)*bmax*cmax + (b+1) *cmax +(c+1)];
7049 en[7]=n_abc[(a )*bmax*cmax + (b+1) *cmax +(c+1)];
7050 #if TEST
7051 printf(" e(%d,%d,%d):%d -> e(%d,%d,%d):%d\n",a,b,c,en[0],a+1,b+1,c+1,en[6]);
7052 printf(" en1: %d %d %d %d \n",en[0],en[1],en[2],en[3]);
7053 printf(" en2: %d %d %d %d \n",en[4],en[5],en[6],en[7]);
7054 #endif
7055 sem_wait(&sem_n);
7056 elem_define(anz,&e_enqire, anz->enext++, 1, en, 0, body[b_indx].eattr );
7057 body[b_indx].elem[k]=anz->emax;
7058 sem_post(&sem_n);
7059
7060 /* RESTART of section mesh-improver, describe variables for the mesh-improver */
7061 for (i=0; i<8; i++)
7062 {
7063 if( n_indx[en[i]]==-1) /* node not stored yet */
7064 {
7065 n_ori[j]=en[i];
7066 sem_wait(&sem_n);
7067 n_coord[j][0]=npre[n_ori[j]].nx;
7068 n_coord[j][1]=npre[n_ori[j]].ny;
7069 n_coord[j][2]=npre[n_ori[j]].nz;
7070 sem_post(&sem_n);
7071 j++;
7072 n_indx[en[i]]=j; /* first number is "1" to match the needs of the improver */
7073 }
7074 #if TEST
7075 printf("en[i]:%d n_indx[en[i]]:%d k:%d i:%d\n", en[i],n_indx[en[i]],k,i);
7076 #endif
7077 e_nod[k][i]=n_indx[en[i]];
7078 }
7079 /* INTERRUPT of section mesh-improver */
7080
7081 k++;
7082 noelem1a:;
7083 }
7084 }
7085 }
7086 }
7087 else if (body[b_indx].etyp==4)
7088 {
7089 for (c=0; c<cmax-1; c+=2)
7090 {
7091 for (a=0; a<amax-1; a+=2)
7092 {
7093 for (b=0; b<bmax-1; b+=2)
7094 {
7095 if ((a>=div_sa1)&&(b<offs_sa1)) goto noelem4a;
7096 if ((a>=div_sa2)&&(b>=bmax-1-offs_sa2)) goto noelem4a;
7097 en[0]=n_abc[(a )*bmax*cmax + b *cmax +c];
7098 en[1]=n_abc[(a+2)*bmax*cmax + b *cmax +c];
7099 en[2]=n_abc[(a+2)*bmax*cmax + (b+2) *cmax +c];
7100 en[3]=n_abc[(a )*bmax*cmax + (b+2) *cmax +c];
7101 en[4]=n_abc[(a )*bmax*cmax + b *cmax +(c+2)];
7102 en[5]=n_abc[(a+2)*bmax*cmax + b *cmax +(c+2)];
7103 en[6]=n_abc[(a+2)*bmax*cmax + (b+2) *cmax +(c+2)];
7104 en[7]=n_abc[(a )*bmax*cmax + (b+2) *cmax +(c+2)];
7105
7106 en[8]=n_abc[(a+1)*bmax*cmax + b *cmax +c];
7107 en[9]=n_abc[(a+2)*bmax*cmax + (b+1) *cmax +c];
7108 en[10]=n_abc[(a+1)*bmax*cmax + (b+2) *cmax +c];
7109 en[11]=n_abc[(a )*bmax*cmax + (b+1) *cmax +c];
7110 en[12]=n_abc[(a )*bmax*cmax + b *cmax +(c+1)];
7111 en[13]=n_abc[(a+2)*bmax*cmax + b *cmax +(c+1)];
7112 en[14]=n_abc[(a+2)*bmax*cmax + (b+2) *cmax +(c+1)];
7113 en[15]=n_abc[(a )*bmax*cmax + (b+2) *cmax +(c+1)];
7114
7115 en[16]=n_abc[(a+1)*bmax*cmax + b *cmax +(c+2)];
7116 en[17]=n_abc[(a+2)*bmax*cmax + (b+1) *cmax +(c+2)];
7117 en[18]=n_abc[(a+1)*bmax*cmax + (b+2) *cmax +(c+2)];
7118 en[19]=n_abc[(a )*bmax*cmax + (b+1) *cmax +(c+2)];
7119 #if TEST
7120 printf(" e(%d,%d,%d):%d -> e(%d,%d,%d):%d\n"
7121 ,a,b,c,en[0],a+2,b+2,c+2,en[6]);
7122 printf(" en1: %d %d %d %d \n",en[0],en[1],en[2],en[3]);
7123 printf(" en2: %d %d %d %d \n",en[4],en[5],en[6],en[7]);
7124 printf(" en3: %d %d %d %d \n",en[8],en[9],en[10],en[11]);
7125 printf(" en4: %d %d %d %d \n",en[12],en[13],en[14],en[15]);
7126 printf(" en5: %d %d %d %d \n",en[16],en[17],en[18],en[19]);
7127 #endif
7128 sem_wait(&sem_n);
7129 elem_define(anz,&e_enqire, anz->enext++, 4, en, 0, body[b_indx].eattr );
7130 body[b_indx].elem[k]=anz->emax;
7131 sem_post(&sem_n);
7132
7133 /* RESTART of section mesh-improver, describe variables for the mesh-improver */
7134 for (i=0; i<20; i++)
7135 {
7136 if( n_indx[en[i]]==-1) /* node not stored yet */
7137 {
7138 n_ori[j]=en[i];
7139 sem_wait(&sem_n);
7140 n_coord[j][0]=npre[n_ori[j]].nx;
7141 n_coord[j][1]=npre[n_ori[j]].ny;
7142 n_coord[j][2]=npre[n_ori[j]].nz;
7143 sem_post(&sem_n);
7144 j++;
7145 n_indx[en[i]]=j; /* first number is "1" to match the needs of the improver */
7146 }
7147 #if TEST
7148 printf("en[i]:%d n_indx[en[i]]:%d k:%d i:%d\n", en[i],n_indx[en[i]],k,i);
7149 #endif
7150 e_nod[k][i]=n_indx[en[i]];
7151 }
7152 /* INTERRUPT of section mesh-improver */
7153
7154 k++;
7155 noelem4a:;
7156 }
7157 }
7158 }
7159 }
7160 body[b_indx].ne=k;
7161
7162 nj=j;
7163
7164 /* RESTART of section mesh-improver: determine the surface and edge nodes */
7165 /* at first the surfs with unbalanced div */
7166
7167 /* side0 only surfs*/
7168 c=0;
7169 for (a=0; a<amax; a++)
7170 {
7171 for (b=0; b<bmax; b++)
7172 {
7173 if ((a>=div_sa1)&&(b<offs_sa1)) ;
7174 else if ((a>=div_sa2)&&(b>bmax-1-offs_sa2)) ;
7175 else
7176 {
7177 s=n_abc[ a *bmax*cmax + b *cmax +c];
7178 if (n_indx[s]>-1) n_type[n_indx[s]]=1;
7179 }
7180 }
7181 }
7182 /* side1 only surfs*/
7183 c=cmax-1;
7184 for (a=0; a<amax; a++)
7185 {
7186 for (b=0; b<bmax; b++)
7187 {
7188 if ((a>=div_sa1)&&(b<offs_sa1)) ;
7189 else if ((a>=div_sa2)&&(b>bmax-1-offs_sa2)) ;
7190 else
7191 {
7192 s=n_abc[ a *bmax*cmax + b *cmax +c];
7193 if (n_indx[s]>-1) n_type[n_indx[s]]=2;
7194 }
7195 }
7196 }
7197 /* side2 */
7198 a=0;
7199 for (c=0; c<cmax; c++)
7200 {
7201 for (b=0; b<bmax; b++)
7202 {
7203 s=n_abc[ a *bmax*cmax + b *cmax +c];
7204 if (n_indx[s]>-1)
7205 {
7206 if(c==0) n_type[n_indx[s]]=-2;
7207 else if(c==cmax-1) n_type[n_indx[s]]=-3;
7208 else if((b==0)||(b==bmax-1)) n_type[n_indx[s]]=-1;
7209 else n_type[n_indx[s]]=3;
7210 }
7211 }
7212 }
7213 /* side3 */
7214 b=0;
7215 for (a=0; a<amax-offs_sa1; a++)
7216 {
7217 for (c=0; c<cmax; c++)
7218 {
7219 s=n_abc[ a *bmax*cmax + b *cmax +c];
7220 if (n_indx[s]>-1)
7221 {
7222 if(c==0) n_type[n_indx[s]]=-2;
7223 else if(c==cmax-1) n_type[n_indx[s]]=-3;
7224 else if((a==0)||(a==amax-1-offs_sa1)) n_type[n_indx[s]]=-1;
7225 else n_type[n_indx[s]]=4;
7226 }
7227 }
7228 }
7229 /* side4 */
7230 a=amax-1;
7231 for (b=offs_sa1; b<bmax-offs_sa2; b++)
7232 {
7233 for (c=0; c<cmax; c++)
7234 {
7235 s=n_abc[ a *bmax*cmax + b *cmax +c];
7236 if (n_indx[s]>-1)
7237 {
7238 if(c==0) n_type[n_indx[s]]=-2;
7239 else if(c==cmax-1) n_type[n_indx[s]]=-3;
7240 else if((b==offs_sa1)||(b==bmax-1-offs_sa2)) n_type[n_indx[s]]=-1;
7241 else n_type[n_indx[s]]=5;
7242 }
7243 }
7244 }
7245 /* side5 */
7246 b=bmax-1;
7247 for (a=0; a<amax-offs_sa2; a++)
7248 {
7249 for (c=0; c<cmax; c++)
7250 {
7251 s=n_abc[ a *bmax*cmax + b *cmax +c];
7252 if (n_indx[s]>-1)
7253 {
7254 if(c==0) n_type[n_indx[s]]=-2;
7255 else if(c==cmax-1) n_type[n_indx[s]]=-3;
7256 else if((a==0)||(a==amax-1-offs_sa2)) n_type[n_indx[s]]=-1;
7257 else n_type[n_indx[s]]=6;
7258 }
7259 }
7260 }
7261 /* for (j=0; j<nj; j++) printf(" n_type[j+1]:%d n_ori[j]:%d \n", n_type[j+1], n_ori[j]); */
7262
7263 /* compiling the edge nodes */
7264 /* side 0 */
7265 v=0;
7266 u=0;
7267 a=0, c=0;
7268 for (b=0; b<bmax-1; b++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7269 s_div[v][0]=b;
7270 b=bmax-1;
7271 for (a=0; a<amax-1-offs_sa2; a++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7272 s_div[v][1]=a;
7273 a=amax-1;
7274 for (b=bmax-1-offs_sa2; b>offs_sa1; b--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7275 s_div[v][2]=bmax-1-offs_sa2-offs_sa1;
7276 b=0;
7277 for (a=amax-1-offs_sa1; a>0; a--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7278 s_div[v][3]=amax-1-offs_sa1;
7279
7280 /* side 1 */
7281 v=1;
7282 u=0;
7283 b=0, c=cmax-1;
7284 for (a=0; a<amax-1-offs_sa1; a++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7285 s_div[v][0]=a;
7286 a=amax-1;
7287 for (b=offs_sa1; b<bmax-1-offs_sa2; b++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7288 s_div[v][1]=b-offs_sa1;
7289 b=bmax-1;
7290 for (a=amax-1-offs_sa2; a>0; a--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7291 s_div[v][2]=amax-1-offs_sa2;
7292 a=0;
7293 for (b=bmax-1; b>0; b--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7294 s_div[v][3]=bmax-1;
7295 /*
7296 for (a=0; a<u; a++) printf("edge[%d][%d]:%d\n", v,a, n_edge[v][a]);
7297 for (a=0; a<4; a++) printf("s_div[%d][%d]:%d\n", v,a, s_div[v][a]);
7298 */
7299
7300 /* side 2 */
7301 v=2;
7302 u=0;
7303 a=b=0;
7304 for (c=0; c<cmax-1; c++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7305 s_div[v][0]=c;
7306 c=cmax-1;
7307 for (b=0; b<bmax-1; b++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7308 s_div[v][1]=b;
7309 b=bmax-1;
7310 for (c=cmax-1; c>0; c--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7311 s_div[v][2]=cmax-1;
7312 c=0;
7313 for (b=bmax-1; b>0; b--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7314 s_div[v][3]=bmax-1;
7315
7316 /* side 3 */
7317 v=3;
7318 u=0;
7319 c=b=0;
7320 for (a=0; a<amax-1-offs_sa1; a++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7321 s_div[v][0]=a;
7322 a=amax-1-offs_sa1;
7323 for (c=0; c<cmax-1; c++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7324 s_div[v][1]=c;
7325 c=cmax-1;
7326 for (a=amax-1-offs_sa1; a>0; a--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7327 s_div[v][2]=amax-1-offs_sa1;
7328 a=0;
7329 for (c=cmax-1; c>0; c--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7330 s_div[v][3]=cmax-1;
7331
7332 /* side 4 */
7333 v=4;
7334 u=0;
7335 a=amax-1; c=0;
7336 for (b=offs_sa1; b<bmax-1-offs_sa2; b++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7337 s_div[v][0]=b-offs_sa1;
7338 b=bmax-1-offs_sa2;
7339 for (c=0; c<cmax-1; c++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7340 s_div[v][1]=c;
7341 c=cmax-1;
7342 for (b=bmax-1-offs_sa2; b>offs_sa1; b--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7343 s_div[v][2]=bmax-1-offs_sa2-offs_sa1;
7344 b=offs_sa1;
7345 for (c=cmax-1; c>0; c--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7346 s_div[v][3]=cmax-1;
7347
7348 /* side 5 */
7349 v=5;
7350 u=0;
7351 c=cmax-1; b=bmax-1;
7352 for (a=0; a<amax-1-offs_sa2; a++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7353 s_div[v][0]=a;
7354 a=amax-1-offs_sa2;
7355 for (c=cmax-1; c>0; c--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7356 s_div[v][1]=cmax-1;
7357 c=0;
7358 for (a=amax-1-offs_sa2; a>0; a--) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7359 s_div[v][2]=amax-1-offs_sa2;
7360 a=0;
7361 for (c=0; c<cmax-1; c++) n_edge[v][u++]=n_indx[n_abc[ a *bmax*cmax + b *cmax +c]];
7362 s_div[v][3]=c;
7363
7364 if(meshImprover( &body[b_indx].etyp, &nj, &k, n_indx, n_ori, n_coord, e_nod, n_type, n_edge, s_div )==0)
7365 {
7366 // write the coordinates back
7367 for (i=0; i<nj; i++)
7368 {
7369 sem_wait(&sem_n);
7370 npre[n_ori[i]].pflag=1;
7371 npre[n_ori[i]].nx=n_coord[i][0];
7372 npre[n_ori[i]].ny=n_coord[i][1];
7373 npre[n_ori[i]].nz=n_coord[i][2];
7374 sem_post(&sem_n);
7375 }
7376 }
7377
7378 /* free some space */
7379 for (i=0; i<(amax*bmax*cmax); i++) free(n_coord[i]);
7380 for (i=0; i<(amax*bmax*cmax); i++) free(e_nod[i]);
7381 for (i=0; i<MAX_SURFS_PER_BODY; i++) free(n_edge[i]);
7382 for (i=0; i<MAX_SURFS_PER_BODY; i++) free(s_div[i]);
7383 free(n_abc);
7384 free(n_indx);
7385 free(n_ori);
7386 free(n_type);
7387 free(e_nod);
7388 free(n_edge);
7389 free(n_coord);
7390 free(s_div);
7391 n_indx=NULL;
7392 n_ori=NULL;
7393 n_type=NULL;
7394 e_nod=NULL;
7395 n_edge=NULL;
7396 n_coord=NULL;
7397 s_div=NULL;
7398 /* END of section mesh-improver */
7399 }
7400 /* body with balanced body-surfs */
7401 else if(body[b_indx].typ==0)
7402 {
7403 umax =body[b_indx].umax;
7404 vmax =body[b_indx].vmax;
7405 wmax =body[b_indx].wmax;
7406 k=0;
7407
7408 if (body[b_indx].etyp==1) /* also for blocked cfd meshes */
7409 {
7410 /* allocate memory for embeded elements */
7411 if((body[b_indx].elem=(int *)realloc((int *)body[b_indx].elem,((umax-1)*(vmax-1)*(wmax-1))*sizeof(int)))==NULL)
7412 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name);
7413 return((void *)0); }
7414
7415 if(writeCFDflag==1)
7416 {
7417
7418 /* ony one thread must be active here per time since apre is everywere used and shared */
7419 sem_wait(&sem_n);
7420
7421 /* allocate memory for final-node-buffer nbuf and the final nodes */
7422 if ((nbuf = (int **)realloc((int **)nbuf, (apre->nmax+1)*sizeof(int *)) ) == NULL )
7423 { printf(" ERROR: realloc failure in meshSurf, nodes not installed\n\n"); return((void *)0); }
7424 for (v=sum_nbuf; v<=apre->nmax; v++)
7425 {
7426 if ((nbuf[v] = (int *)malloc( (2)*sizeof(int)) ) == NULL )
7427 { printf(" ERROR: realloc failure in meshSurf, nodes not installed\n\n"); return((void *)0); }
7428 nbuf[v][0]=0;
7429 }
7430 sum_nbuf=apre->nmax+1;
7431
7432 /* store the node-indexes for block-structured cfd meshes */
7433 if(body[b_indx].ori!='+')
7434 {
7435 printf("WARNING: for cfd the body:%s must be positive oriented but is negative oriented.\n", body[b_indx].name);
7436 }
7437
7438 printf("# body:%s is duns-body:%d\n", body[b_indx].name, b_indx+1);
7439 if ( (nBlock = (NodeBlocks *)realloc((NodeBlocks *)nBlock, (apre->b+1) * sizeof(NodeBlocks))) == NULL )
7440 printf("\n\n ERROR: realloc failed, NodeBlocks\n\n") ;
7441 if ( (nBlock[apre->b].nod = (int *)malloc( (umax*vmax*wmax+1) * sizeof(int))) == NULL )
7442 printf("\n\n ERROR: malloc failed, NodeBlocks\n\n") ;
7443 nBlock[apre->b].dim=3;
7444 nBlock[apre->b].geo=b_indx;
7445 nBlock[apre->b].i=umax;
7446 nBlock[apre->b].j=vmax;
7447 nBlock[apre->b].k=wmax;
7448 n=0;
7449 for (w=0; w<wmax; w++)
7450 {
7451 for (v=0; v<vmax; v++)
7452 {
7453 for (u=0; u<umax; u++)
7454 {
7455 nBlock[apre->b].nod[n]=n_uvw[u*vmax*wmax+v*wmax+w];
7456 n++;
7457 }
7458 }
7459 }
7460
7461 /* determine the connectivity for cfd-blocks */
7462 if(body[b_indx].ns!=6)
7463 {
7464 printf("PRG_ERROR: body must have 6 surfaces but has:%d. Please check your model.\n",body[b_indx].ns);
7465 exit(1);
7466 }
7467 for (v=0; v<body[b_indx].ns; v++)
7468 {
7469 /* v: side-nr in duns and isaac */
7470 /* duns-surfs are imin, imax, jmin, jmax, (kmin, kmax) */
7471 /* ii: cgx surfaces */
7472 if(v==0) ii=0;
7473 else if(v==1) ii=1;
7474 else if(v==2) ii=3;
7475 else if(v==3) ii=5;
7476 else if(v==4) ii=2;
7477 else ii=4;
7478
7479 nBlock[apre->b].neighbor[v]=-1;
7480 nBlock[apre->b].bcface[v]=-1;
7481 nBlock[apre->b].map[v][0]=-1; nBlock[apre->b].map[v][1]=-1; nBlock[apre->b].map[v][2]=-1;
7482
7483 /* describe the contact face by indexes */
7484 /* faces related to bcp[0]: ii= 0,2,3 */
7485 /* faces related to bcp[6]: ii= 1,4,5 */
7486 /* i==nBlock[].strt1[face][0], j==nBlock[].strt1[face][1], j==nBlock[].strt1[face][2] */
7487 imax= umax; jmax= vmax; kmax= wmax;
7488 if(ii==0)
7489 {
7490 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
7491 nBlock[apre->b].end_1[v][0]=1; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=kmax;
7492 }
7493 if(ii==1)
7494 {
7495 nBlock[apre->b].strt1[v][0]=imax; nBlock[apre->b].strt1[v][1]=jmax; nBlock[apre->b].strt1[v][2]=kmax;
7496 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=1; nBlock[apre->b].end_1[v][2]=1;
7497 }
7498 if(ii==2)
7499 {
7500 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
7501 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=1;
7502 }
7503 if(ii==3)
7504 {
7505 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
7506 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=1; nBlock[apre->b].end_1[v][2]=kmax;
7507 }
7508 if(ii==4)
7509 {
7510 nBlock[apre->b].strt1[v][0]=imax; nBlock[apre->b].strt1[v][1]=jmax; nBlock[apre->b].strt1[v][2]=kmax;
7511 nBlock[apre->b].end_1[v][0]=1; nBlock[apre->b].end_1[v][1]=1; nBlock[apre->b].end_1[v][2]=kmax;
7512 }
7513 if(ii==5)
7514 {
7515 nBlock[apre->b].strt1[v][0]=imax; nBlock[apre->b].strt1[v][1]=jmax; nBlock[apre->b].strt1[v][2]=kmax;
7516 nBlock[apre->b].end_1[v][0]=1; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=1;
7517 }
7518
7519 surFlag=1;
7520
7521 /* search the slave surface */
7522 for (u=0; u<set[setNr].anz_b; u++)
7523 {
7524 if((u!=b_indx)&&(body[u].name != (char *)NULL)) for (jj=0; jj<body[u].ns; jj++)
7525 {
7526
7527 if (body[b_indx].s[ii]==body[u].s[jj])
7528 {
7529 /* corresponding body */
7530 surFlag=0;
7531 #if TEST2
7532 printf(" b:%s s:%s matches b:%s\n", body[b_indx].name, surf[body[b_indx].s[ii]].name, body[u].name);
7533 #endif
7534 /* determine the corner-points of the corresponding body */
7535 if( generateBodyCornerPoints( u, bcp2, srefp) == -1) goto noEtypDefined;
7536 iislave=jj;
7537 #if TEST2
7538 printf ("Edgepoints of Body:%s ", body[u].name );
7539 for (j=0; j<MAX_CORNERS_PER_BODY; j++)
7540 printf (" j:%d bcp:%d %s", j, bcp2[j], point[bcp2[j]].name);
7541 printf ("\n");
7542 for (j=0; j<MAX_SURFS_PER_BODY; j++)
7543 printf (" surf %d %s", j,surf[body[u].s[j]].name );
7544 printf ("\n");
7545
7546 /* determine the orientation of the corresponding body */
7547 printf(" ii:%d iislave:%d\n", ii, iislave);
7548 #endif
7549 /* check if the corresponding body is usable for cfd */
7550 /* and determine the amount of nodes in each direction of the slave body */
7551 for(j=0; j<body[u].ns; j++)
7552 {
7553 unbalance[j]= getSurfDivs( u, j, &div_lu[j][0] );
7554 if (unbalance[j]!=0) surFlag=1;
7555 }
7556 goto matchSurfs;
7557 }
7558 }
7559 }
7560 matchSurfs:;
7561
7562
7563 if(!surFlag)
7564 {
7565 nBlock[apre->b].neighbor[v]=u;
7566
7567 /* determine the parametric space of the slave body */
7568 /* suche die Eckpunkte der surfaces, setzt einen orientierten body voraus. */
7569 /* so das die punktefolge der linienfolge entspricht */
7570 if( generateBodyCornerPoints( u, bcp3, srefp) == -1) goto noEtypDefined;
7571
7572 /* surfs are all balanced, determine umax etc. */
7573 s=0;
7574 if (body[u].o[s]=='+')
7575 {
7576 if ((srefp[s]==0)||(srefp[s]==2))
7577 {
7578 kmax=div_lu[s][0]+1;
7579 jmax=div_lu[s][1]+1;
7580 }
7581 else if ((srefp[s]==1)||(srefp[s]==3))
7582 {
7583 kmax=div_lu[s][1]+1;
7584 jmax=div_lu[s][0]+1;
7585 }
7586 else
7587 {
7588 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
7589 exit(-1);
7590 }
7591 }
7592 else
7593 {
7594 if ((srefp[s]==0)||(srefp[s]==2))
7595 {
7596 kmax=div_lu[s][1]+1;
7597 jmax=div_lu[s][0]+1;
7598 }
7599 else if ((srefp[s]==1)||(srefp[s]==3))
7600 {
7601 kmax=div_lu[s][0]+1;
7602 jmax=div_lu[s][1]+1;
7603 }
7604 else
7605 {
7606 errMsg(" ERROR: edge%d not known:%d\n",s, srefp[s]);
7607 exit(-1);
7608 }
7609 }
7610
7611 /* bestimme die parametrischen Kantenlaengen des bodies, s3 fuer u,w */
7612 s=3;
7613 /* n=srefp[3]; ist gleich der LinienNr die die u-achse beschreibt, wenn die ori. der surf '+' ist */
7614 n=srefp[s]; /* Body-Surf edgenr */
7615 if (body[u].o[s]=='-')
7616 {
7617 if( n==0) n=3;
7618 else if( n==1) n=0;
7619 else if( n==2) n=1;
7620 else if( n==3) n=2;
7621 }
7622 imax=div_lu[s][n]+1;
7623
7624
7625 if((ii==0)&&(iislave==0))
7626 {
7627 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=2; }
7628 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=3; }
7629 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=5; }
7630 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=6; }
7631 else printf("ERROR in orienting the corresponding body\n");
7632 }
7633 else if((ii==0)&&(iislave==1))
7634 {
7635 if (bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=2; }
7636 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=6; }
7637 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=5; }
7638 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=3; }
7639 else printf("ERROR in orienting the corresponding body\n");
7640 }
7641 else if((ii==0)&&(iislave==2))
7642 {
7643 if (bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=2; }
7644 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=4; }
7645 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=5; }
7646 else if(bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=1; }
7647 else printf("ERROR in orienting the corresponding body\n");
7648 }
7649 else if((ii==0)&&(iislave==3))
7650 {
7651 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=3; }
7652 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=1; }
7653 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=6; }
7654 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=4; }
7655 else printf("ERROR in orienting the corresponding body\n");
7656 }
7657 else if((ii==0)&&(iislave==4))
7658 {
7659 if (bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=2; }
7660 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=1; }
7661 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=5; }
7662 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=4; }
7663 else printf("ERROR in orienting the corresponding body\n");
7664 }
7665 else if((ii==0)&&(iislave==5))
7666 {
7667 if (bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=6; }
7668 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=1; }
7669 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=3; }
7670 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=4; }
7671 else printf("ERROR in orienting the corresponding body\n");
7672 }
7673
7674 else if((ii==2)&&(iislave==0))
7675 {
7676 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=2; }
7677 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=3; }
7678 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=5; }
7679 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=6; }
7680 else printf("ERROR in orienting the corresponding body\n");
7681 }
7682 else if((ii==2)&&(iislave==1))
7683 {
7684 if (bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=2; }
7685 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=6; }
7686 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=5; }
7687 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=3; }
7688 else printf("ERROR in orienting the corresponding body\n");
7689 }
7690 else if((ii==2)&&(iislave==2))
7691 {
7692 if (bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=2; }
7693 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=4; }
7694 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=5; }
7695 else if(bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=1; }
7696 else printf("ERROR in orienting the corresponding body\n");
7697 }
7698 else if((ii==2)&&(iislave==3))
7699 {
7700 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=3; }
7701 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=1; }
7702 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=6; }
7703 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=4; }
7704 else printf("ERROR in orienting the corresponding body\n");
7705 }
7706 else if((ii==2)&&(iislave==4))
7707 {
7708 if (bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=2; }
7709 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=1; }
7710 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=5; }
7711 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=4; }
7712 else printf("ERROR in orienting the corresponding body\n");
7713 }
7714 else if((ii==2)&&(iislave==5))
7715 {
7716 if (bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=6; }
7717 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=1; }
7718 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=3; }
7719 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=4; }
7720 else printf("ERROR in orienting the corresponding body\n");
7721 }
7722
7723 else if((ii==3)&&(iislave==0))
7724 {
7725 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=2; }
7726 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=3; }
7727 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=5; }
7728 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=6; }
7729 else printf("ERROR in orienting the corresponding body\n");
7730 }
7731 else if((ii==3)&&(iislave==1))
7732 {
7733 if (bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=2; }
7734 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=6; }
7735 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=5; }
7736 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=3; }
7737 else printf("ERROR in orienting the corresponding body\n");
7738 }
7739 else if((ii==3)&&(iislave==2))
7740 {
7741 if (bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=2; }
7742 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=4; }
7743 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=5; }
7744 else if(bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=1; }
7745 else printf("ERROR in orienting the corresponding body\n");
7746 }
7747 else if((ii==3)&&(iislave==3))
7748 {
7749 if (bcp2[0]==bcp[0]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=3; }
7750 else if(bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=1; }
7751 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=6; }
7752 else if(bcp2[4]==bcp[0]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=4; }
7753 else printf("ERROR in orienting the corresponding body\n");
7754 }
7755 else if((ii==3)&&(iislave==4))
7756 {
7757 if (bcp2[3]==bcp[0]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=2; }
7758 else if(bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=1; }
7759 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=5; }
7760 else if(bcp2[7]==bcp[0]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=4; }
7761 else printf("ERROR in orienting the corresponding body\n");
7762 }
7763 else if((ii==3)&&(iislave==5))
7764 {
7765 if (bcp2[2]==bcp[0]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=6; }
7766 else if(bcp2[1]==bcp[0]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=1; }
7767 else if(bcp2[5]==bcp[0]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=3; }
7768 else if(bcp2[6]==bcp[0]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=4; }
7769 else printf("ERROR in orienting the corresponding body\n");
7770 }
7771
7772 else if((ii==1)&&(iislave==0))
7773 {
7774 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=2; }
7775 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=3; }
7776 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=5; }
7777 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=6; }
7778 else printf("ERROR in orienting the corresponding body\n");
7779 }
7780 else if((ii==1)&&(iislave==1))
7781 {
7782 if (bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=2; }
7783 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=6; }
7784 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=5; }
7785 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=3; }
7786 else printf("ERROR in orienting the corresponding body\n");
7787 }
7788 else if((ii==1)&&(iislave==2))
7789 {
7790 if (bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=2; }
7791 else if(bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=4; }
7792 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=5; }
7793 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=1; }
7794 else printf("ERROR in orienting the corresponding body\n");
7795 }
7796 else if((ii==1)&&(iislave==3))
7797 {
7798 if (bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=3; }
7799 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=1; }
7800 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=6; }
7801 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=4; }
7802 else printf("ERROR in orienting the corresponding body\n");
7803 }
7804 else if((ii==1)&&(iislave==4))
7805 {
7806 if (bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=2; }
7807 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=1; }
7808 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=5; }
7809 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=4; }
7810 else printf("ERROR in orienting the corresponding body\n");
7811 }
7812 else if((ii==1)&&(iislave==5))
7813 {
7814 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=6; }
7815 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=1; }
7816 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=3; }
7817 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=4; }
7818 else printf("ERROR in orienting the corresponding body\n");
7819 }
7820
7821 else if((ii==4)&&(iislave==0))
7822 {
7823 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=2; }
7824 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=3; }
7825 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=5; }
7826 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=6; }
7827 else printf("ERROR in orienting the corresponding body\n");
7828 }
7829 else if((ii==4)&&(iislave==1))
7830 {
7831 if (bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=2; }
7832 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=6; }
7833 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=5; }
7834 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=3; }
7835 else printf("ERROR in orienting the corresponding body\n");
7836 }
7837 else if((ii==4)&&(iislave==2))
7838 {
7839 if (bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=2; }
7840 else if(bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=4; }
7841 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=5; }
7842 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=1; }
7843 else printf("ERROR in orienting the corresponding body\n");
7844 }
7845 else if((ii==4)&&(iislave==3))
7846 {
7847 if (bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=3; }
7848 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=1; }
7849 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=6; }
7850 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=4; }
7851 else printf("ERROR in orienting the corresponding body\n");
7852 }
7853 else if((ii==4)&&(iislave==4))
7854 {
7855 if (bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=2; }
7856 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=2; nBlock[apre->b].map[v][1]=1; }
7857 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=5; }
7858 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=5; nBlock[apre->b].map[v][1]=4; }
7859 else printf("ERROR in orienting the corresponding body\n");
7860 }
7861 else if((ii==4)&&(iislave==5))
7862 {
7863 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=4; nBlock[apre->b].map[v][1]=6; }
7864 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=6; nBlock[apre->b].map[v][1]=1; }
7865 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=1; nBlock[apre->b].map[v][1]=3; }
7866 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=3; nBlock[apre->b].map[v][1]=4; }
7867 else printf("ERROR in orienting the corresponding body\n");
7868 }
7869
7870 else if((ii==5)&&(iislave==0))
7871 {
7872 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=2; }
7873 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=3; }
7874 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=5; }
7875 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][1]=1; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=6; }
7876 else printf("ERROR in orienting the corresponding body\n");
7877 }
7878 else if((ii==5)&&(iislave==1))
7879 {
7880 if (bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=2; }
7881 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=6; }
7882 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=5; }
7883 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][1]=4; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=3; }
7884 else printf("ERROR in orienting the corresponding body\n");
7885 }
7886 else if((ii==5)&&(iislave==2))
7887 {
7888 if (bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=2; }
7889 else if(bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=4; }
7890 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=5; }
7891 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][1]=3; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=1; }
7892 else printf("ERROR in orienting the corresponding body\n");
7893 }
7894 else if((ii==5)&&(iislave==3))
7895 {
7896 if (bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=3; }
7897 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=1; }
7898 else if(bcp2[4]==bcp[6]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=6; }
7899 else if(bcp2[0]==bcp[6]) { nBlock[apre->b].map[v][1]=2; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=4; }
7900 else printf("ERROR in orienting the corresponding body\n");
7901 }
7902 else if((ii==5)&&(iislave==4))
7903 {
7904 if (bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=2; }
7905 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=2; nBlock[apre->b].map[v][0]=1; }
7906 else if(bcp2[7]==bcp[6]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=5; }
7907 else if(bcp2[3]==bcp[6]) { nBlock[apre->b].map[v][1]=6; nBlock[apre->b].map[v][2]=5; nBlock[apre->b].map[v][0]=4; }
7908 else printf("ERROR in orienting the corresponding body\n");
7909 }
7910 else if((ii==5)&&(iislave==5))
7911 {
7912 if (bcp2[1]==bcp[6]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=4; nBlock[apre->b].map[v][0]=6; }
7913 else if(bcp2[5]==bcp[6]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=6; nBlock[apre->b].map[v][0]=1; }
7914 else if(bcp2[6]==bcp[6]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=1; nBlock[apre->b].map[v][0]=3; }
7915 else if(bcp2[2]==bcp[6]) { nBlock[apre->b].map[v][1]=5; nBlock[apre->b].map[v][2]=3; nBlock[apre->b].map[v][0]=4; }
7916 else printf("ERROR in orienting the corresponding body\n");
7917 }
7918 else printf("ERROR: no adjacent body-face found\n");
7919
7920 /* count the block-to-block interfaces for isaac */
7921 apre->c++;
7922
7923
7924 if((iislave==0) && ((ii==0)||(ii==2)||(ii==3)) )
7925 {
7926 if (bcp2[0]==bcp[0])
7927 {
7928 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
7929 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
7930 }
7931 else if(bcp2[1]==bcp[0])
7932 {
7933 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
7934 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
7935 }
7936 else if(bcp2[2]==bcp[0])
7937 {
7938 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
7939 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
7940 }
7941 else if(bcp2[3]==bcp[0])
7942 {
7943 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
7944 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
7945 }
7946 else printf("ERROR in orienting the corresponding body\n");
7947 }
7948 if((iislave==0) && ((ii==1)||(ii==4)||(ii==5)) )
7949 {
7950 if (bcp2[0]==bcp[6])
7951 {
7952 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
7953 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
7954 }
7955 else if(bcp2[1]==bcp[6])
7956 {
7957 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
7958 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
7959 }
7960 else if(bcp2[2]==bcp[6])
7961 {
7962 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
7963 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
7964 }
7965 else if(bcp2[3]==bcp[6])
7966 {
7967 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
7968 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
7969 }
7970 else printf("ERROR in orienting the corresponding body\n");
7971 }
7972
7973 if((iislave==1) && ((ii==0)||(ii==2)||(ii==3)) )
7974 {
7975 if (bcp2[4]==bcp[0])
7976 {
7977 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
7978 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
7979 }
7980 else if(bcp2[5]==bcp[0])
7981 {
7982 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
7983 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
7984 }
7985 else if(bcp2[6]==bcp[0])
7986 {
7987 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
7988 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
7989 }
7990 else if(bcp2[7]==bcp[0])
7991 {
7992 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
7993 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
7994 }
7995 else printf("ERROR in orienting the corresponding body\n");
7996 }
7997 if((iislave==1) && ((ii==1)||(ii==4)||(ii==5)) )
7998 {
7999 if (bcp2[4]==bcp[6])
8000 {
8001 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8002 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8003 }
8004 else if(bcp2[5]==bcp[6])
8005 {
8006 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8007 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8008 }
8009 else if(bcp2[6]==bcp[6])
8010 {
8011 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8012 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8013 }
8014 else if(bcp2[7]==bcp[6])
8015 {
8016 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8017 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8018 }
8019 else printf("ERROR in orienting the corresponding body\n");
8020 }
8021
8022 if((iislave==2) && ((ii==0)||(ii==2)||(ii==3)) )
8023 {
8024 if (bcp2[0]==bcp[0])
8025 {
8026 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8027 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8028 }
8029 else if(bcp2[1]==bcp[0])
8030 {
8031 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8032 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8033 }
8034 else if(bcp2[5]==bcp[0])
8035 {
8036 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8037 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8038 }
8039 else if(bcp2[4]==bcp[0])
8040 {
8041 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8042 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8043 }
8044 else printf("ERROR in orienting the corresponding body\n");
8045 }
8046 if((iislave==2) && ((ii==1)||(ii==4)||(ii==5)) )
8047 {
8048 if (bcp2[0]==bcp[6])
8049 {
8050 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8051 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8052 }
8053 else if(bcp2[1]==bcp[6])
8054 {
8055 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8056 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8057 }
8058 else if(bcp2[5]==bcp[6])
8059 {
8060 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8061 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8062 }
8063 else if(bcp2[4]==bcp[6])
8064 {
8065 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8066 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8067 }
8068 else printf("ERROR in orienting the corresponding body\n");
8069 }
8070
8071 if((iislave==4) && ((ii==0)||(ii==2)||(ii==3)) )
8072 {
8073 if (bcp2[3]==bcp[0])
8074 {
8075 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8076 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8077 }
8078 else if(bcp2[2]==bcp[0])
8079 {
8080 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8081 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8082 }
8083 else if(bcp2[6]==bcp[0])
8084 {
8085 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8086 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8087 }
8088 else if(bcp2[7]==bcp[0])
8089 {
8090 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8091 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8092 }
8093 else printf("ERROR in orienting the corresponding body\n");
8094 }
8095 if((iislave==4) && ((ii==1)||(ii==4)||(ii==5)) )
8096 {
8097 if (bcp2[3]==bcp[6])
8098 {
8099 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8100 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8101 }
8102 else if(bcp2[2]==bcp[6])
8103 {
8104 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8105 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8106 }
8107 else if(bcp2[6]==bcp[6])
8108 {
8109 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8110 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8111 }
8112 else if(bcp2[7]==bcp[6])
8113 {
8114 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8115 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8116 }
8117 else printf("ERROR in orienting the corresponding body\n");
8118 }
8119
8120 if((iislave==3) && ((ii==0)||(ii==2)||(ii==3)) )
8121 {
8122 if (bcp2[0]==bcp[0])
8123 {
8124 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8125 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8126 }
8127 else if(bcp2[4]==bcp[0])
8128 {
8129 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8130 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8131 }
8132 else if(bcp2[7]==bcp[0])
8133 {
8134 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8135 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8136 }
8137 else if(bcp2[3]==bcp[0])
8138 {
8139 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8140 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8141 }
8142 else printf("ERROR in orienting the corresponding body\n");
8143 }
8144 if((iislave==3) && ((ii==1)||(ii==4)||(ii==5)) )
8145 {
8146 if (bcp2[0]==bcp[6])
8147 {
8148 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8149 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8150 }
8151 else if(bcp2[4]==bcp[6])
8152 {
8153 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=1;
8154 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=kmax;
8155 }
8156 else if(bcp2[7]==bcp[6])
8157 {
8158 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8159 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8160 }
8161 else if(bcp2[3]==bcp[6])
8162 {
8163 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=1; nBlock[apre->b].strt2[v][2]=kmax;
8164 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=1; nBlock[apre->b].end_2[v][2]=1;
8165 }
8166 else printf("ERROR in orienting the corresponding body\n");
8167 }
8168
8169 if((iislave==5) && ((ii==0)||(ii==2)||(ii==3)) )
8170 {
8171 if (bcp2[1]==bcp[0])
8172 {
8173 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8174 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8175 }
8176 else if(bcp2[5]==bcp[0])
8177 {
8178 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8179 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8180 }
8181 else if(bcp2[6]==bcp[0])
8182 {
8183 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8184 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8185 }
8186 else if(bcp2[2]==bcp[0])
8187 {
8188 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8189 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8190 }
8191 else printf("ERROR in orienting the corresponding body\n");
8192 }
8193 if((iislave==5) && ((ii==1)||(ii==4)||(ii==5)) )
8194 {
8195 if (bcp2[1]==bcp[6])
8196 {
8197 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8198 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8199 }
8200 else if(bcp2[5]==bcp[6])
8201 {
8202 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=1;
8203 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=kmax;
8204 }
8205 else if(bcp2[6]==bcp[6])
8206 {
8207 nBlock[apre->b].strt2[v][0]=imax; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8208 nBlock[apre->b].end_2[v][0]=1; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8209 }
8210 else if(bcp2[2]==bcp[6])
8211 {
8212 nBlock[apre->b].strt2[v][0]=1; nBlock[apre->b].strt2[v][1]=jmax; nBlock[apre->b].strt2[v][2]=kmax;
8213 nBlock[apre->b].end_2[v][0]=imax; nBlock[apre->b].end_2[v][1]=jmax; nBlock[apre->b].end_2[v][2]=1;
8214 }
8215 else printf("ERROR in orienting the corresponding body\n");
8216 }
8217
8218 }
8219
8220 if(surFlag)
8221 {
8222 /* found a free surface */
8223 printf("# surf:%s is duns-surf:%d \n", surf[body[b_indx].s[ii]].name, anz_cfdSurfs+1 );
8224 nBlock[apre->b].neighbor[v]=anz_cfdSurfs+1;
8225 nBlock[apre->b].bcface[v]=ii;
8226 anz_cfdSurfs++;
8227
8228 /* i==nBlock[].strt1[][0], j==nBlock[].strt1[][1], imin==1, imax==vmax, jmin==1, jmax==umax */
8229 /* i,j,k must be ascending, therefore they must be newly written! */
8230 imax= umax; jmax= vmax; kmax= wmax;
8231 if(ii==0)
8232 {
8233 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
8234 nBlock[apre->b].end_1[v][0]=1; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=kmax;
8235 }
8236 if(ii==1)
8237 {
8238 nBlock[apre->b].strt1[v][0]=imax; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
8239 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=kmax;
8240 }
8241 if(ii==2)
8242 {
8243 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
8244 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=1;
8245 }
8246 if(ii==3)
8247 {
8248 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=1;
8249 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=1; nBlock[apre->b].end_1[v][2]=kmax;
8250 }
8251 if(ii==4)
8252 {
8253 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=1; nBlock[apre->b].strt1[v][2]=kmax;
8254 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=kmax;
8255 }
8256 if(ii==5)
8257 {
8258 nBlock[apre->b].strt1[v][0]=1; nBlock[apre->b].strt1[v][1]=jmax; nBlock[apre->b].strt1[v][2]=1;
8259 nBlock[apre->b].end_1[v][0]=imax; nBlock[apre->b].end_1[v][1]=jmax; nBlock[apre->b].end_1[v][2]=kmax;
8260 }
8261 }
8262 }
8263
8264 for (w=0; w<wmax; w++)
8265 {
8266 for (v=0; v<vmax; v++)
8267 {
8268 for (u=0; u<umax; u++)
8269 {
8270 nod( anz, &node, 1, anz->nnext++, npre[n_uvw[u*vmax*wmax+v*wmax+w]].nx, npre[n_uvw[u*vmax*wmax+v*wmax+w]].ny, npre[n_uvw[u*vmax*wmax+v*wmax+w]].nz, 0 );
8271 if(nbuf[n_uvw[u*vmax*wmax+v*wmax+w]][0]>0)
8272 {
8273 if ((nbuf[n_uvw[u*vmax*wmax+v*wmax+w]] = (int *)realloc((int *)nbuf[n_uvw[u*vmax*wmax+v*wmax+w]], (nbuf[n_uvw[u*vmax*wmax+v*wmax+w]][0]+2)*sizeof(int)) ) == NULL )
8274 { printf(" ERROR: realloc failure in meshSurf, nodes not installed\n\n"); return((void *)0); }
8275 }
8276 nbuf[n_uvw[u*vmax*wmax+v*wmax+w]][0]++; nbuf[n_uvw[u*vmax*wmax+v*wmax+w]][nbuf[n_uvw[u*vmax*wmax+v*wmax+w]][0]]=anz->nnext-1;
8277 }
8278 }
8279 }
8280 apre->b++;
8281
8282 sem_post(&sem_n);
8283
8284 }
8285 /* end cfd */
8286
8287
8288 for (w=0; w<wmax-1; w++)
8289 {
8290 for (v=0; v<vmax-1; v++)
8291 {
8292 for (u=0; u<umax-1; u++)
8293 {
8294 en[0]=n_uvw[ u*vmax*wmax + v*wmax + w ];
8295 en[1]=n_uvw[ u*vmax*wmax + v*wmax + (w+1) ];
8296 en[2]=n_uvw[ (u+1)*vmax*wmax + v*wmax + (w+1) ];
8297 en[3]=n_uvw[ (u+1)*vmax*wmax + v*wmax + w ];
8298 en[4]=n_uvw[ u*vmax*wmax + (v+1)*wmax + w ];
8299 en[5]=n_uvw[ u*vmax*wmax + (v+1)*wmax + (w+1) ];
8300 en[6]=n_uvw[ (u+1)*vmax*wmax + (v+1)*wmax + (w+1) ];
8301 en[7]=n_uvw[ (u+1)*vmax*wmax + (v+1)*wmax + w ];
8302 sem_wait(&sem_n);
8303 elem_define(anz,&e_enqire, anz->enext++, 1, en, 0, body[b_indx].eattr );
8304 body[b_indx].elem[k]=anz->emax;
8305 sem_post(&sem_n);
8306 k++;
8307 }
8308 }
8309 }
8310 }
8311
8312 else if (body[b_indx].etyp==4)
8313 {
8314 /* allocate memory for embeded elements */
8315 if((body[b_indx].elem=(int *)realloc((int *)body[b_indx].elem,((umax-1)*(vmax-1)*(wmax-1)/8)*sizeof(int)))==NULL)
8316 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[b_indx].name);
8317 return((void *)0); }
8318 for (w=0; w<wmax-2; w+=2)
8319 {
8320 for (v=0; v<vmax-2; v+=2)
8321 {
8322 for (u=0; u<umax-2; u+=2)
8323 {
8324 en[0]=n_uvw[ (u )*vmax*wmax + (v )*wmax + (w ) ];
8325 en[1]=n_uvw[ (u )*vmax*wmax + (v )*wmax + (w+2) ];
8326 en[2]=n_uvw[ (u+2)*vmax*wmax + (v )*wmax + (w+2) ];
8327 en[3]=n_uvw[ (u+2)*vmax*wmax + (v )*wmax + (w ) ];
8328 en[4]=n_uvw[ (u )*vmax*wmax + (v+2)*wmax + (w ) ];
8329 en[5]=n_uvw[ (u )*vmax*wmax + (v+2)*wmax + (w+2) ];
8330 en[6]=n_uvw[ (u+2)*vmax*wmax + (v+2)*wmax + (w+2) ];
8331 en[7]=n_uvw[ (u+2)*vmax*wmax + (v+2)*wmax + (w ) ];
8332
8333 en[8] =n_uvw[ (u )*vmax*wmax + (v )*wmax + (w+1) ];
8334 en[9] =n_uvw[ (u+1)*vmax*wmax + (v )*wmax + (w+2) ];
8335 en[10]=n_uvw[ (u+2)*vmax*wmax + (v )*wmax + (w+1) ];
8336 en[11]=n_uvw[ (u+1)*vmax*wmax + (v )*wmax + (w ) ];
8337 en[12]=n_uvw[ (u )*vmax*wmax + (v+1)*wmax + (w ) ];
8338 en[13]=n_uvw[ (u )*vmax*wmax + (v+1)*wmax + (w+2) ];
8339 en[14]=n_uvw[ (u+2)*vmax*wmax + (v+1)*wmax + (w+2) ];
8340 en[15]=n_uvw[ (u+2)*vmax*wmax + (v+1)*wmax + (w ) ];
8341
8342 en[16]=n_uvw[ (u )*vmax*wmax + (v+2)*wmax + (w+1) ];
8343 en[17]=n_uvw[ (u+1)*vmax*wmax + (v+2)*wmax + (w+2) ];
8344 en[18]=n_uvw[ (u+2)*vmax*wmax + (v+2)*wmax + (w+1) ];
8345 en[19]=n_uvw[ (u+1)*vmax*wmax + (v+2)*wmax + (w ) ];
8346 en[20]=n_uvw[ (u )*vmax*wmax + (v+1)*wmax + (w+1) ];
8347 en[21]=n_uvw[ (u+1)*vmax*wmax + (v+1)*wmax + (w+2) ];
8348 en[22]=n_uvw[ (u+2)*vmax*wmax + (v+1)*wmax + (w+1) ];
8349 en[23]=n_uvw[ (u+1)*vmax*wmax + (v+1)*wmax + (w ) ];
8350
8351 en[24]=n_uvw[ (u+1)*vmax*wmax + (v+0)*wmax + (w+1) ];
8352 en[25]=n_uvw[ (u+1)*vmax*wmax + (v+2)*wmax + (w+1) ];
8353 sem_wait(&sem_n);
8354 elem_define(anz,&e_enqire, anz->enext++, 4, en, 0, body[b_indx].eattr );
8355 body[b_indx].elem[k]=anz->emax;
8356 sem_post(&sem_n);
8357 k++;
8358 }
8359 }
8360 }
8361 }
8362 body[b_indx].ne=k;
8363 free(n_uvw);
8364 }
8365
8366 /* if a substitute body was meshed then map the mesh onto the original one, body will be deleted later */
8367 if(mapbody[bod]>-1)
8368 {
8369 #if TEST
8370 printf("MAP MESH TO BODY :%s\n", body[set[setNr].body[bod]].name);
8371 #endif
8372 s=set[setNr].body[bod];
8373 if((body[s].elem=(int *)realloc((int *)body[s].elem, (body[b_indx].ne)*sizeof(int)) )==NULL)
8374 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[s].name); seta(set_nomesh, "b", s); noBodyMesh++; }
8375 for(k=0; k<body[b_indx].ne; k++) body[s].elem[k]=body[b_indx].elem[k];
8376 body[s].ne=body[b_indx].ne;
8377
8378 if((body[s].nod=(int *)realloc((int *)body[s].nod, (body[b_indx].nn)*sizeof(int)) )==NULL)
8379 { printf(" ERROR: realloc failure body:%s can not be meshed\n\n", body[s].name); seta(set_nomesh, "b", s); noBodyMesh++; }
8380 for(k=0; k<body[b_indx].nn; k++) body[s].nod[k]=body[b_indx].nod[k];
8381 body[s].nn=body[b_indx].nn;
8382 body[s].fail=0;
8383 }
8384
8385 body[b_indx].fail=0;
8386 continue;
8387 badBody:;
8388 noEtypDefined:;
8389 body[b_indx].fail=1;
8390 seta(set_nomesh, "b", b_indx);
8391 noBodyMesh++;
8392 }
8393
8394 param->vargp[5]=noBodyMesh;
8395 return((void *)1);
8396 }
8397
8398
8399 /**********************************************************************************/
8400 /* */
8401 /* creates temporary-nodes and final elements in all bodies */
8402 /* */
8403 /**********************************************************************************/
meshBodies(int setNr)8404 int meshBodies( int setNr )
8405 {
8406 int i,bod;
8407 int noBodyMesh=0, anz_b, b_indx;
8408 static int *mapbody=NULL;
8409
8410 typedef struct {
8411 int vargp[6];
8412 int *mapbody;
8413 } Threadargs;
8414 Threadargs *targ=NULL;
8415 pthread_t *tid=NULL;
8416 int nlocalThreads;
8417
8418 /* save the amount of bodies to be meshed */
8419 anz_b=set[setNr].anz_b;
8420
8421 /* buffer for substituted bodies */
8422 if ((mapbody = (int *)realloc((int *)mapbody, (anz_b+1)*sizeof(int)) ) == NULL )
8423 { printf(" ERROR: realloc failure\n\n"); }
8424 for (bod=0; bod<anz_b; bod++) mapbody[bod]=-1;
8425
8426 for (bod=0; bod<anz_b; bod++)
8427 {
8428 b_indx=set[setNr].body[bod];
8429 body[b_indx].fail=1;
8430 if( body[b_indx].name == (char *)NULL ) continue;
8431
8432 if ((body[b_indx].etyp==1)||(body[b_indx].etyp==4))
8433 {
8434 if(printFlag) printf ("meshing body:%s with %d surfs\n", body[b_indx].name, body[b_indx].ns);
8435 }
8436 else
8437 {
8438 continue;
8439 }
8440
8441 /* check how much surfs define the body. If not 6 then create a substitute-body with 6 surfs */
8442 if(body[b_indx].ns==5)
8443 {
8444 if(bodyFrom5Surfs(&b_indx)==-1) body[b_indx].fail=1;
8445 else body[b_indx].fail=0;
8446 mapbody[bod]=b_indx;
8447 }
8448 else if(body[b_indx].ns==7)
8449 {
8450 if(bodyFrom7Surfs(&b_indx)==-1) body[b_indx].fail=1;
8451 else body[b_indx].fail=0;
8452 mapbody[bod]=b_indx;
8453 }
8454 else if (body[b_indx].ns!=6)
8455 {
8456 errMsg (" ERROR: , body:%s has %d surfs but must have 5 to 7!\n", body[b_indx].name, body[b_indx].ns);
8457 }
8458 else
8459 {
8460 body[b_indx].fail=0;
8461 }
8462 }
8463
8464 /*
8465 for (bod=0; bod<anz_b; bod++)
8466 {
8467 if(mapbody[bod]>-1) printf("bodies to map %d %d \n",bod, mapbody[bod]);
8468 }
8469 */
8470
8471 /* threaded body evaluation */
8472 if(anz->threads>anz_b) { nlocalThreads=anz_b; }
8473 else nlocalThreads=anz->threads;
8474 if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
8475 if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
8476 for(i=0; i<nlocalThreads; i++)
8477 {
8478 targ[i].vargp[0]=setNr;
8479 targ[i].vargp[1]=anz_b;
8480 targ[i].vargp[3]=0; // unused
8481 targ[i].vargp[4]=i;
8482 targ[i].mapbody=mapbody;
8483 //printf(" thread:%d bodies\n",i);
8484 pthread_create(&tid[i],NULL,thread_genNodeFromBody,(void *)&targ[i]);
8485 }
8486 for(i=0; i<nlocalThreads; i++)
8487 {
8488 pthread_join(tid[i], NULL);
8489 }
8490 glob_bod=0;
8491
8492 free(tid); tid=NULL;
8493 free(targ); targ=NULL;
8494
8495 return(noBodyMesh);
8496 }
8497
8498
8499
meshSet(char * setname,int blockFlag,int lonlyFlag,int projFlag,int meshoptFlag_length,int meshoptFlag_angle)8500 int meshSet(char *setname, int blockFlag, int lonlyFlag, int projFlag, int meshoptFlag_length, int meshoptFlag_angle )
8501 {
8502 int setNr, i,j,k, n=0,e=0,p,l,s,b, anz_n, buf, sets, renderFlag=0;
8503 double xn, yn, zn;
8504
8505 int *ptr=NULL, *nodbuf=NULL;
8506 int **pointnod=NULL, **linenod=NULL, **surfnod=NULL, **bodynod=NULL;
8507 int *pointnods=NULL, *linenods=NULL, *surfnods=NULL, *bodynods=NULL;
8508 int **lineelem=NULL, **surfelem=NULL, **bodyelem=NULL;
8509 int *lineelems=NULL, *surfelems=NULL, *bodyelems=NULL;
8510 int ini_anz_e;
8511
8512 #if TEST
8513 /* file fuer debugging infos */
8514 handle= fopen("fort.30","w+");
8515 #endif
8516
8517 nurbsflag=projFlag;
8518 meshopt_length=meshoptFlag_length;
8519 meshopt_angle=meshoptFlag_angle;
8520 oldmeshflag=lonlyFlag;
8521
8522 writeCFDflag=blockFlag;
8523 anz_cfdSurfs=0;
8524 sum_nbuf=0;
8525
8526 /* clear special sets */
8527 delSet(specialset->nomesh );
8528 set_nomesh=pre_seta(specialset->nomesh, "i", 0);
8529
8530 setNr=getSetNr(setname);
8531 if (setNr<0)
8532 {
8533 printf (" ERROR in meshSet: set:%s does not exist\n", setname);
8534 return(-1);
8535 }
8536 apre->n=0;
8537 apre->e=0;
8538 apre->f=0;
8539 apre->g=0;
8540 apre->emax=0;
8541 apre->emin=MAX_INTEGER;
8542 apre->b=0;
8543 apre->c=0;
8544 apre->l=0;
8545 apre->nmax=0;
8546 apre->nmin=MAX_INTEGER;
8547 apre->nnext=1;
8548 apre->enext=1;
8549 apre->orign=0;
8550 npre=NULL;
8551 ini_anz_e=anz->e;
8552
8553 /* so far blocked meshing for cfd is only working with one thread */
8554 if(writeCFDflag==1) anz->threads=1;
8555
8556 /* repaint the surface for the interior definitions (uv-loops) before the mesh is created */
8557 /* but only if tr3g, tr3u or tr6u are requested */
8558 for (j=0; j<set[setNr].anz_s; j++)
8559 {
8560 i=set[setNr].surf[j];
8561 if(((surf[i].etyp==7)||(surf[i].etyp==8))&&(surf[i].sh>-1)&&(surf[i].eattr<0))
8562 {
8563 if(shape[surf[i].sh].type==4) repNurs(shape[surf[i].sh].p[0]);
8564 // repSurf performed in mesh_tr3u
8565 }
8566 }
8567
8568 /* All surfaces with no assigned elem-type which reference a shape or nurbs should have the unstructured mesh attribute */
8569 /*-> but not if the surface is used by a body which does not use the ustructured mesh attribute */
8570 if ( set[setNr].anz_s>0)
8571 {
8572 for(i=0; i<set[setNr].anz_s; i++)
8573 {
8574 j=set[setNr].surf[i];
8575 if((surf[j].etyp==0)&&(surf[j].eattr==0)&&(surf[j].sh!=-1)) surf[j].eattr=-1;
8576 }
8577 }
8578 if ( set[setNr].anz_b>0)
8579 {
8580 for(i=0; i<set[setNr].anz_b; i++)
8581 {
8582 b=set[setNr].body[i];
8583 if(body[b].eattr!=-1)
8584 {
8585 for(j=0; j<body[b].ns; j++)
8586 {
8587 p=body[b].s[j];
8588 if((surf[p].etyp==0)&&(surf[p].eattr==-1)) surf[p].eattr=0;
8589 }
8590 }
8591 }
8592 }
8593
8594
8595 if ( set[setNr].anz_p>0)
8596 {
8597 // save the node references
8598 if ((pointnods = (int *)malloc(set[setNr].anz_p*sizeof(int)) ) == NULL )
8599 { printf(" ERROR: malloc failure\n\n"); }
8600 if ((pointnod = (int **)malloc(set[setNr].anz_p*sizeof(int *)) ) == NULL )
8601 { printf(" ERROR: malloc failure\n\n"); }
8602 for(i=0; i<set[setNr].anz_p; i++)
8603 {
8604 p=set[setNr].pnt[i];
8605 if(point[p].nn)
8606 {
8607 if ((pointnod[i] = (int *)malloc(point[p].nn*sizeof(int)) ) == NULL )
8608 { printf(" ERROR: malloc failure\n\n"); }
8609 for(j=0; j<point[p].nn; j++) pointnod[i][j]=point[p].nod[j];
8610 pointnods[i]=point[p].nn;
8611 }
8612 else pointnods[i]=0;
8613 }
8614 buf= meshPoints(setNr, renderFlag) ;
8615 if (buf<0) { errMsg(" Nothing to do! Specify element types with elty.\n"); return(-2); }
8616 }
8617 if ( set[setNr].anz_l>0)
8618 {
8619 // save the node references
8620 if ((linenods = (int *)malloc(set[setNr].anz_l*sizeof(int)) ) == NULL )
8621 { printf(" ERROR: malloc failure\n\n"); }
8622 if ((linenod = (int **)malloc(set[setNr].anz_l*sizeof(int *)) ) == NULL )
8623 { printf(" ERROR: malloc failure\n\n"); }
8624 // save the element references
8625 if ((lineelems = (int *)malloc(set[setNr].anz_l*sizeof(int)) ) == NULL )
8626 { printf(" ERROR: malloc failure\n\n"); }
8627 if ((lineelem = (int **)malloc(set[setNr].anz_l*sizeof(int *)) ) == NULL )
8628 { printf(" ERROR: malloc failure\n\n"); }
8629 for(i=0; i<set[setNr].anz_l; i++)
8630 {
8631 p=set[setNr].line[i];
8632 if(line[p].nn)
8633 {
8634 if ((linenod[i] = (int *)malloc(line[p].nn*sizeof(int)) ) == NULL )
8635 { printf(" ERROR: malloc failure\n\n"); }
8636 for(j=0; j<line[p].nn; j++) linenod[i][j]=line[p].nod[j];
8637 linenods[i]=line[p].nn;
8638 }
8639 else linenods[i]=0;
8640 if(line[p].ne)
8641 {
8642 if ((lineelem[i] = (int *)malloc(line[p].ne*sizeof(int)) ) == NULL )
8643 { printf(" ERROR: malloc failure\n\n"); }
8644 for(j=0; j<line[p].ne; j++) lineelem[i][j]=line[p].elem[j];
8645 lineelems[i]=line[p].ne;
8646 }
8647 else lineelems[i]=0;
8648 }
8649 buf=meshLines( setNr, renderFlag);
8650 if (buf<0) { errMsg(" ERROR: severe problem in meshLines \n"); return(-3); }
8651 else if (buf>0) errMsg(" %d lines are not meshed, check set %s \n", buf,specialset->nomesh);
8652 }
8653 if ( set[setNr].anz_s>0)
8654 {
8655 // save the node references
8656 if ((surfnods = (int *)malloc(set[setNr].anz_s*sizeof(int)) ) == NULL )
8657 { printf(" ERROR: malloc failure\n\n"); }
8658 if ((surfnod = (int **)malloc(set[setNr].anz_s*sizeof(int *)) ) == NULL )
8659 { printf(" ERROR: malloc failure\n\n"); }
8660 // save the element references
8661 if ((surfelems = (int *)malloc(set[setNr].anz_s*sizeof(int)) ) == NULL )
8662 { printf(" ERROR: malloc failure\n\n"); }
8663 if ((surfelem = (int **)malloc(set[setNr].anz_s*sizeof(int *)) ) == NULL )
8664 { printf(" ERROR: malloc failure\n\n"); }
8665 for(i=0; i<set[setNr].anz_s; i++)
8666 {
8667 p=set[setNr].surf[i];
8668 if(surf[p].nn)
8669 {
8670 if ((surfnod[i] = (int *)malloc(surf[p].nn*sizeof(int)) ) == NULL )
8671 { printf(" ERROR: malloc failure\n\n"); }
8672 for(j=0; j<surf[p].nn; j++) surfnod[i][j]=surf[p].nod[j];
8673 surfnods[i]=surf[p].nn;
8674 }
8675 else surfnods[i]=0;
8676 if(surf[p].ne)
8677 {
8678 if ((surfelem[i] = (int *)malloc(surf[p].ne*sizeof(int)) ) == NULL )
8679 { printf(" ERROR: malloc failure\n\n"); }
8680 for(j=0; j<surf[p].ne; j++) surfelem[i][j]=surf[p].elem[j];
8681 surfelems[i]=surf[p].ne;
8682 }
8683 else surfelems[i]=0;
8684 }
8685 buf=meshSurfs( setNr, renderFlag);
8686 if (buf<0) { errMsg(" ERROR: severe problem in meshSurfs \n"); return(-4); }
8687 else if (buf>0) errMsg(" %d surfs are not meshed, check set %s \n", buf,specialset->nomesh);
8688 }
8689 if ( set[setNr].anz_b>0)
8690 {
8691 // save the node references
8692 if ((bodynods = (int *)malloc(set[setNr].anz_b*sizeof(int)) ) == NULL )
8693 { printf(" ERROR: malloc failure\n\n"); }
8694 if ((bodynod = (int **)malloc(set[setNr].anz_b*sizeof(int *)) ) == NULL )
8695 { printf(" ERROR: malloc failure\n\n"); }
8696 // save the element references
8697 if ((bodyelems = (int *)malloc(set[setNr].anz_b*sizeof(int)) ) == NULL )
8698 { printf(" ERROR: malloc failure\n\n"); }
8699 if ((bodyelem = (int **)malloc(set[setNr].anz_b*sizeof(int *)) ) == NULL )
8700 { printf(" ERROR: malloc failure\n\n"); }
8701 for(i=0; i<set[setNr].anz_b; i++)
8702 {
8703 p=set[setNr].body[i];
8704 if(body[p].nn)
8705 {
8706 if ((bodynod[i] = (int *)malloc(body[p].nn*sizeof(int)) ) == NULL )
8707 { printf(" ERROR: malloc failure\n\n"); }
8708 for(j=0; j<body[p].nn; j++) bodynod[i][j]=body[p].nod[j];
8709 bodynods[i]=body[p].nn;
8710 }
8711 else bodynods[i]=0;
8712 if(body[p].ne)
8713 {
8714 if ((bodyelem[i] = (int *)malloc(body[p].ne*sizeof(int)) ) == NULL )
8715 { printf(" ERROR: malloc failure\n\n"); }
8716 for(j=0; j<body[p].ne; j++) bodyelem[i][j]=body[p].elem[j];
8717 bodyelems[i]=body[p].ne;
8718 }
8719 else bodyelems[i]=0;
8720 }
8721 buf=meshBodies( setNr) ;
8722 if (buf<0) { errMsg(" ERROR: severe problem \n"); return(-5); }
8723 else if (buf>0) errMsg(" %d bodies are not meshed, check set %s \n", buf,specialset->nomesh);
8724 }
8725 for (i=0; i<anzGeo->nurs; i++) untrimNurs(i);
8726
8727 /* delete specialset->nomesh if nothing was stored */
8728 if((!set[set_nomesh].anz_l)&&(!set[set_nomesh].anz_s)&&(!set[set_nomesh].anz_s)) delSet(specialset->nomesh);
8729
8730 /* --------------- all elements are allocated, allocate final nodes ----------------- */
8731
8732 /* reset all node references if it is no block mesh */
8733 if(!blockFlag)
8734 {
8735 if(nbuf==NULL)
8736 {
8737 if ((nbuf = (int **)realloc((int **)nbuf, (apre->nmax+1)*sizeof(int *)) ) == NULL )
8738 { printf(" ERROR: realloc failure in meshLines, nodes not installed\n\n"); return(-1); }
8739 for (i=sum_nbuf; i<=apre->nmax; i++)
8740 {
8741 if ((nbuf[i] = (int *)malloc( (2)*sizeof(int)) ) == NULL )
8742 { printf(" ERROR: malloc failure\n\n"); return(-1); }
8743 nbuf[i][0]=0;
8744 }
8745 }
8746 else
8747 {
8748 for (i=0; i<=apre->nmax; i++)
8749 {
8750 nbuf[i][0]=0;
8751 }
8752 }
8753 }
8754
8755 #if TEST
8756 /* zum testen koennen npre uebernommen werden, funktioniert nicht bei mehrstufiger Vernetzung */
8757 printf("zum testen werden npre uebernommen\n");
8758 if( anz->nmax )
8759 {
8760 errMsg("ERROR: in meshSet, no TEST possible with a predefined mesh (anz->nmax==%d)\n", anz->nmax );
8761 goto nextSet;
8762 }
8763 if( apre->n > 0 )
8764 {
8765 for (i=1; i<=apre->nmax; i++)
8766 {
8767 nod( anz, &node, 1, i, npre[i].nx, npre[i].ny, npre[i].nz , 0 );
8768 nbuf[i][0]=1; nbuf[i][1]=i;
8769 }
8770 }
8771 #else
8772 for (i=ini_anz_e; i<anz->e; i++)
8773 {
8774 if(e_enqire[e_enqire[i].nr].type==1)
8775 {
8776 for (j=0; j<8; j++)
8777 {
8778 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8779 {
8780 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n"
8781 , e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8782 e_enqire[e_enqire[i].nr].nod[j]= 1;
8783 }
8784 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8785 {
8786 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8787 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8788 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8789 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8790 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8791 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8792 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8793 }
8794 else /* node is allocated */
8795 {
8796 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8797 }
8798 }
8799 }
8800 if(e_enqire[e_enqire[i].nr].type==4)
8801 {
8802 for (j=0; j<20; j++)
8803 {
8804 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8805 {
8806 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8807 e_enqire[e_enqire[i].nr].nod[j]= 1;
8808 }
8809 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8810 {
8811 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8812 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8813 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8814 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8815 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8816 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8817 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8818 }
8819 else /* node is allocated */
8820 {
8821 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8822 }
8823 }
8824 }
8825 if(e_enqire[e_enqire[i].nr].type==7)
8826 {
8827 for (j=0; j<3; j++)
8828 {
8829 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8830 {
8831 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8832 e_enqire[e_enqire[i].nr].nod[j]= 1;
8833 }
8834 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8835 {
8836 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8837 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8838 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8839 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8840 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8841 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8842 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8843 }
8844 else /* node is allocated */
8845 {
8846 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8847 }
8848 }
8849 }
8850 if(e_enqire[e_enqire[i].nr].type==8)
8851 {
8852 for (j=0; j<6; j++)
8853 {
8854 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8855 {
8856 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8857 e_enqire[e_enqire[i].nr].nod[j]= 1;
8858 }
8859 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8860 {
8861 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8862 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8863 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8864 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8865 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8866 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8867 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8868 }
8869 else /* node is allocated */
8870 {
8871 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8872 }
8873 }
8874 }
8875 if(e_enqire[e_enqire[i].nr].type==9)
8876 {
8877 for (j=0; j<4; j++)
8878 {
8879 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8880 {
8881 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8882 e_enqire[e_enqire[i].nr].nod[j]= 1;
8883 }
8884 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8885 {
8886 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8887 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8888 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8889 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8890 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8891 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8892 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8893 }
8894 else /* node is allocated */
8895 {
8896 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8897 }
8898 }
8899 }
8900 if(e_enqire[e_enqire[i].nr].type==10)
8901 {
8902 for (j=0; j<8; j++)
8903 {
8904 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8905 {
8906 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8907 e_enqire[e_enqire[i].nr].nod[j]= 1;
8908 }
8909 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8910 {
8911 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8912 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8913 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8914 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8915 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8916 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8917 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8918 }
8919 else /* node is allocated */
8920 {
8921 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8922 }
8923 }
8924 }
8925 if(e_enqire[e_enqire[i].nr].type==11)
8926 {
8927 for (j=0; j<2; j++)
8928 {
8929 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8930 {
8931 printf(" ERROR: en:%d > apre->nmax:%d, e:%d corrupted\n", e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8932 e_enqire[e_enqire[i].nr].nod[j]= 1;
8933 }
8934 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8935 {
8936 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8937 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8938 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8939 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8940 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8941 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8942 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8943 }
8944 else /* node is allocated */
8945 {
8946 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8947 }
8948 }
8949 }
8950 if(e_enqire[e_enqire[i].nr].type==12)
8951 {
8952 for (j=0; j<3; j++)
8953 {
8954 if ((e_enqire[e_enqire[i].nr].nod[j]>apre->nmax)||(e_enqire[e_enqire[i].nr].nod[j]<0))
8955 {
8956 printf(" ERROR: en[%d]:%d > apre->nmax:%d, e:%d corrupted\n", i, e_enqire[e_enqire[i].nr].nod[j],apre->nmax,e_enqire[i].nr);
8957 e_enqire[e_enqire[i].nr].nod[j]= 1;
8958 }
8959 else if ( nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]==0 ) /* node not yet allocated */
8960 {
8961 xn=npre[e_enqire[e_enqire[i].nr].nod[j]].nx;
8962 yn=npre[e_enqire[e_enqire[i].nr].nod[j]].ny;
8963 zn=npre[e_enqire[e_enqire[i].nr].nod[j]].nz;
8964 nod( anz, &node, 1, anz->nnext, xn, yn, zn, 0 );
8965 nbuf[e_enqire[e_enqire[i].nr].nod[j]][0]=1;
8966 nbuf[e_enqire[e_enqire[i].nr].nod[j]][1]= anz->nnext;
8967 e_enqire[e_enqire[i].nr].nod[j]= anz->nnext++;
8968 }
8969 else /* node is allocated */
8970 {
8971 e_enqire[e_enqire[i].nr].nod[j]= nbuf[e_enqire[e_enqire[i].nr].nod[j]][1];
8972 }
8973 }
8974 }
8975 }
8976 #endif
8977
8978 /* replace n_pre by node in all cfd-blocks */
8979 if(printFlag) printf(" update the node numbers of the cfd-blocks\n");
8980 if ( apre->b>0)
8981 {
8982 anz->b=apre->b;
8983 anz->c=apre->c;
8984 for (i=0; i<anz->b; i++)
8985 {
8986 for (n=0; n<(nBlock[i].i*nBlock[i].j*nBlock[i].k); n++ )
8987 {
8988 nBlock[i].nod[n]=nbuf[nBlock[i].nod[n]][1];
8989 }
8990 }
8991 }
8992
8993 /* replace n_pre by node in all entities */
8994 if(printFlag) printf(" update the node numbers of the geometric entities\n");
8995 if ( set[setNr].anz_p>0)
8996 {
8997 for (i=0; i<set[setNr].anz_p; i++)
8998 {
8999 anz_n=0;
9000 p=set[setNr].pnt[i];
9001 for (n=0; n<point[p].nn; n++ )
9002 {
9003 #if TEST
9004 if ((point[p].nod[n]>apre->nmax)||(point[p].nod[n]<0))
9005 {
9006 errMsg("ERROR: point[%d].nod[%d]=%d not valid\n",p,n,point[p].nod[n]);
9007 }
9008 #endif
9009 j=0; while(j<nbuf[point[p].nod[n]][0])
9010 {
9011 if ((nodbuf = (int *)realloc((int *)nodbuf, (anz_n+1)*sizeof(int)) ) == NULL )
9012 { printf("\n\nERROR: realloc failure in meshSet\n\n"); return(0); }
9013 nodbuf[anz_n]=nbuf[point[p].nod[n]][++j]; anz_n++;
9014 }
9015 }
9016 point[p].nn=anz_n;
9017 ptr=point[p].nod;
9018 point[p].nod=nodbuf;
9019 nodbuf=ptr;
9020 }
9021 }
9022
9023 if ( set[setNr].anz_l>0)
9024 {
9025 for (i=0; i<set[setNr].anz_l; i++)
9026 {
9027 anz_n=0;
9028 l=set[setNr].line[i];
9029 for (n=0; n<line[l].nn; n++ )
9030 {
9031 #if TEST
9032 if ((line[l].nod[n]>apre->nmax)||(line[l].nod[n]<0))
9033 {
9034 errMsg("ERROR: line[%d].nod[%d]=%d not valid\n",l,n,line[l].nod[n]);
9035 }
9036 #endif
9037 j=0; while(j<nbuf[line[l].nod[n]][0])
9038 {
9039 if ((nodbuf = (int *)realloc((int *)nodbuf, (anz_n+1)*sizeof(int)) ) == NULL )
9040 { printf("\n\nERROR: realloc failure in meshSet\n\n"); return(0); }
9041 nodbuf[anz_n]=nbuf[line[l].nod[n]][++j]; anz_n++;
9042 }
9043 }
9044 line[l].nn=anz_n;
9045 ptr=line[l].nod;
9046 line[l].nod=nodbuf;
9047 nodbuf=ptr;
9048 }
9049 }
9050
9051 if ( set[setNr].anz_s>0)
9052 {
9053 for (i=0; i<set[setNr].anz_s; i++)
9054 {
9055 anz_n=0;
9056 s=set[setNr].surf[i];
9057 for (n=0; n<surf[s].nn; n++ )
9058 {
9059 #if TEST
9060 if ((surf[s].nod[n]>apre->nmax)||(surf[s].nod[n]<0))
9061 {
9062 errMsg("ERROR: surf[%d].nod[%d]=%d not valid\n",s,n,surf[s].nod[n]);
9063 }
9064 #endif
9065 j=0; while(j<nbuf[surf[s].nod[n]][0])
9066 {
9067 if ((nodbuf = (int *)realloc((int *)nodbuf, (anz_n+1)*sizeof(int)) ) == NULL )
9068 { printf("\n\nERROR: realloc failure in meshSet\n\n"); return(0); }
9069 nodbuf[anz_n]=nbuf[surf[s].nod[n]][++j]; anz_n++;
9070 }
9071 }
9072 surf[s].nn=anz_n;
9073 ptr=surf[s].nod;
9074 surf[s].nod=nodbuf;
9075 nodbuf=ptr;
9076 }
9077 }
9078
9079 if ( set[setNr].anz_b>0)
9080 {
9081 for (i=0; i<set[setNr].anz_b; i++)
9082 {
9083 anz_n=0;
9084 b=set[setNr].body[i];
9085 for (n=0; n<body[b].nn; n++ )
9086 {
9087 #if TEST
9088 if ((body[b].nod[n]>apre->nmax)||(body[b].nod[n]<1))
9089 {
9090 errMsg("ERROR: body[%d].nod[%d]=%d not valid\n",b,n,body[b].nod[n]);
9091 }
9092 #endif
9093 j=0; while(j<nbuf[body[b].nod[n]][0])
9094 {
9095 if ((nodbuf = (int *)realloc((int *)nodbuf, (anz_n+1)*sizeof(int)) ) == NULL )
9096 { printf("\n\nERROR: realloc failure in meshSet\n\n"); return(0); }
9097 nodbuf[anz_n]=nbuf[body[b].nod[n]][++j]; anz_n++;
9098 }
9099 }
9100 body[b].nn=anz_n;
9101 ptr=body[b].nod;
9102 body[b].nod=nodbuf;
9103 nodbuf=ptr;
9104 }
9105 }
9106
9107 /* delete the temporary entities which were created to substitute 3- and 5-sided surfs */
9108 /* warning, s is now redefined */
9109 if(printFlag) printf(" delete the temporary entities\n");
9110 s=getSetNr(specialset->zap);
9111 #if TEST
9112 fclose(handle);
9113 #else
9114 if(s>-1)
9115 {
9116 for(i=0; i<set[s].anz_b; i++)
9117 {
9118 if(printFlag) printf (" delete body:%s \n", body[set[s].body[i]].name );
9119 for(j=0; j<anz->sets; j++)
9120 {
9121 if(set[j].flag=='o') setr( j, "b",set[s].body[i] );
9122 }
9123 body[set[s].body[i]].name = (char *)NULL ;
9124 body[set[s].body[i]].ns=0;
9125 free(body[set[s].body[i]].o);
9126 body[set[s].body[i]].o= NULL;
9127 free(body[set[s].body[i]].s);
9128 body[set[s].body[i]].s= NULL;
9129 body[set[s].body[i]].nn=0;
9130 free(body[set[s].body[i]].nod);
9131 body[set[s].body[i]].nod= NULL;
9132 body[set[s].body[i]].ne=0;
9133 free(body[set[s].body[i]].elem);
9134 body[set[s].body[i]].elem= NULL;
9135 body[set[s].body[i]].etyp= 0;
9136 }
9137 for(i=0; i<set[s].anz_s; i++)
9138 {
9139 if(printFlag) printf (" delete surf:%s \n", surf[set[s].surf[i]].name );
9140 for(j=0; j<anz->sets; j++)
9141 {
9142 if(set[j].flag=='o') setr( j, "s",set[s].surf[i] );
9143 }
9144 surf[set[s].surf[i]].name = (char *)NULL ;
9145 surf[set[s].surf[i]].nl= 0;
9146 free(surf[set[s].surf[i]].typ);
9147 surf[set[s].surf[i]].typ= NULL;
9148 free(surf[set[s].surf[i]].o);
9149 surf[set[s].surf[i]].o= NULL;
9150 free(surf[set[s].surf[i]].l);
9151 surf[set[s].surf[i]].l= NULL;
9152 surf[set[s].surf[i]].nn= 0;
9153 free(surf[set[s].surf[i]].nod);
9154 surf[set[s].surf[i]].nod= NULL;
9155 surf[set[s].surf[i]].ne= 0;
9156 free(surf[set[s].surf[i]].elem);
9157 surf[set[s].surf[i]].elem= NULL;
9158 surf[set[s].surf[i]].etyp= 0;
9159 }
9160 for(i=0; i<set[s].anz_l; i++)
9161 {
9162 if(printFlag) printf (" delete line:%s \n", line[set[s].line[i]].name );
9163 /* setr will also remove node-numbers of n_pre from set 'all' */
9164 /* this node-numbers might be used by predefined nodes also */
9165 /* therefore a 'comp all do' must follow to compensate this */
9166 for(j=0; j<anz->sets; j++)
9167 {
9168 if(set[j].flag=='o') setr( j, "l",set[s].line[i] );
9169 }
9170 line[set[s].line[i]].name = (char *)NULL ;
9171 line[set[s].line[i]].div = 0;
9172 if (line[set[s].line[i]].typ=='s')
9173 {
9174 /* delete the set */
9175 delSet(set[line[set[s].line[i]].trk].name);
9176 }
9177 line[set[s].line[i]].typ=' ';
9178 line[set[s].line[i]].etyp=0;
9179 line[set[s].line[i]].p1=-1;
9180 line[set[s].line[i]].p2=-1;
9181 line[set[s].line[i]].trk=-1;
9182 line[set[s].line[i]].nip= 0;
9183 free(line[set[s].line[i]].ip);
9184 line[set[s].line[i]].ip= NULL;
9185 line[set[s].line[i]].nn= 0;
9186 free(line[set[s].line[i]].nod);
9187 line[set[s].line[i]].nod = NULL;
9188 line[set[s].line[i]].ne= 0;
9189 free(line[set[s].line[i]].elem);
9190 line[set[s].line[i]].elem = NULL;
9191 }
9192 for(i=0; i<set[s].anz_c; i++)
9193 {
9194 if(printFlag) printf (" delete lcmb:%s \n", lcmb[set[s].lcmb[i]].name );
9195 for(j=0; j<anz->sets; j++)
9196 {
9197 if(set[j].flag=='o') setr( j, "c",set[s].lcmb[i] );
9198 }
9199 lcmb[set[s].lcmb[i]].name = (char *)NULL;
9200 lcmb[set[s].lcmb[i]].nl=0;
9201 free(lcmb[set[s].lcmb[i]].o);
9202 lcmb[set[s].lcmb[i]].o= NULL;
9203 free(lcmb[set[s].lcmb[i]].l);
9204 lcmb[set[s].lcmb[i]].l= NULL;
9205 lcmb[set[s].lcmb[i]].p1=-1;
9206 lcmb[set[s].lcmb[i]].p2=-1;
9207 }
9208 for(i=0; i<set[s].anz_p; i++)
9209 {
9210 if(printFlag) printf (" delete pnt:%s \n", point[set[s].pnt[i]].name );
9211 for(j=0; j<anz->sets; j++)
9212 {
9213 if(set[j].flag=='o') setr( j, "p",set[s].pnt[i] );
9214 }
9215 point[set[s].pnt[i]].name = (char *)NULL ;
9216 free(point[set[s].pnt[i]].nod);
9217 point[set[s].pnt[i]].nod=NULL;
9218 point[set[s].pnt[i]].nn=0;
9219 }
9220 /* delete the set itself */
9221 //delSet(specialset->zap);
9222
9223 /* the following commands includes the lost nodes in set all */
9224 s=pre_seta( specialset->zap, "i", 0 );
9225 setall=getSetNr("all");
9226 if(setall>=0)
9227 {
9228 if((set[s].elem=(int *)realloc((int *)set[s].elem,(set[s].anz_e+set[setall].anz_e+1)*sizeof(int)))==NULL)
9229 printf(" ERROR: malloc failed in set[%d]:%s\n\n", 0, set[s].name);
9230 for(i=0; i<set[setall].anz_e; i++)
9231 {
9232 set[s].elem[set[s].anz_e]= set[setall].elem[i]; set[s].anz_e++;
9233 }
9234 qsort( set[s].elem, set[s].anz_e, sizeof(int), (void *)compareInt );
9235 }
9236 /* circle through all elements and add all nodes */
9237 for (i=0; i<set[s].anz_e; i++)
9238 {
9239 if (e_enqire[set[s].elem[i]].type == 1) n = 8; /* HEXA8 */
9240 else if (e_enqire[set[s].elem[i]].type == 2) n = 6; /* PENTA6 */
9241 else if (e_enqire[set[s].elem[i]].type == 3) n = 4; /* TET4 */
9242 else if (e_enqire[set[s].elem[i]].type == 4) n = 20; /* HEXA20 */
9243 else if (e_enqire[set[s].elem[i]].type == 5) n = 15; /* PENTA15 */
9244 else if (e_enqire[set[s].elem[i]].type == 6) n = 10; /* TET10 */
9245 else if (e_enqire[set[s].elem[i]].type == 7) n = 3; /* TRI3 */
9246 else if (e_enqire[set[s].elem[i]].type == 8) n = 6; /* TRI6 */
9247 else if (e_enqire[set[s].elem[i]].type == 9) n = 4; /* QUAD4 */
9248 else if (e_enqire[set[s].elem[i]].type == 10) n = 8; /* QUAD8 */
9249 else if (e_enqire[set[s].elem[i]].type == 11) n = 2; /* BEAM2 */
9250 else if (e_enqire[set[s].elem[i]].type == 12) n = 3; /* BEAM3 */
9251 else n=0;
9252 if((set[s].node=(int *)realloc((int *)set[s].node,(set[s].anz_n+n+1)*sizeof(int)))==NULL)
9253 printf(" ERROR: malloc failed in set[%d]:%s\n\n", 0, set[s].name);
9254 for (j=0; j<n; j++)
9255 {
9256 set[s].node[set[s].anz_n]= e_enqire[set[s].elem[i]].nod[j]; set[s].anz_n++;
9257 }
9258 }
9259 qsort( set[s].node, set[s].anz_n, sizeof(int), (void *)compareInt );
9260
9261 for(i=0; i<set[s].anz_n; i++) if(!node[set[s].node[i]].pflag)
9262 {
9263 seta(setall,"n",set[s].node[i]);
9264 }
9265
9266 delSet(specialset->zap);
9267 }
9268 #endif
9269
9270 /* add the nodes of entities to the sets */
9271 for (sets=0; sets<anz->sets; sets++)
9272 {
9273 if ( sets==setNr||( set[sets].type==1)||(set[sets].name==(char *)NULL)) goto nextSet;
9274 n=set[sets].anz_n;
9275 e=set[sets].anz_e;
9276
9277 if ( set[sets].anz_p>0)
9278 {
9279 for (i=0; i<set[sets].anz_p; i++)
9280 {
9281 p=set[sets].pnt[i];
9282 if((point[p].name != (char *)NULL)&&(point[p].nn>0))
9283 {
9284 for (k=0; k<point[p].nn; k++)
9285 {
9286 if(node[point[p].nod[k]].pflag!=-1 )
9287 {
9288 set[sets].anz_n++;
9289 if((set[sets].node=(int *)realloc((int *)set[sets].node, (set[sets].anz_n)*sizeof(int)))==NULL)
9290 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9291 set[sets].node[n++]=point[p].nod[k];
9292 }
9293 }
9294 }
9295 }
9296 }
9297 if ( set[sets].anz_l>0)
9298 {
9299 for (i=0; i<set[sets].anz_l; i++)
9300 {
9301 l=set[sets].line[i];
9302 if(line[l].name != (char *)NULL)
9303 {
9304 for (k=0; k<line[l].nn; k++)
9305 {
9306 if(node[line[l].nod[k]].pflag!=-1 )
9307 {
9308 set[sets].anz_n++;
9309 if((set[sets].node=(int *)realloc((int *)set[sets].node, (set[sets].anz_n)*sizeof(int)))==NULL)
9310 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9311 set[sets].node[n++]=line[l].nod[k];
9312 }
9313 }
9314 for (k=0; k<line[l].ne; k++)
9315 {
9316 if(e_enqire[line[l].elem[k]].type)
9317 {
9318 set[sets].anz_e++;
9319 if((set[sets].elem=(int *)realloc((int *)set[sets].elem, (set[sets].anz_e)*sizeof(int)))==NULL)
9320 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9321 set[sets].elem[e++]=line[l].elem[k];
9322 }
9323 }
9324 }
9325 }
9326 }
9327 if ( set[sets].anz_s>0)
9328 {
9329 for (i=0; i<set[sets].anz_s; i++)
9330 {
9331 s=set[sets].surf[i];
9332 if(surf[s].name != (char *)NULL)
9333 {
9334 for (k=0; k<surf[s].nn; k++)
9335 {
9336 if(node[surf[s].nod[k]].pflag!=-1 )
9337 {
9338 set[sets].anz_n++;
9339 if((set[sets].node=(int *)realloc((int *)set[sets].node, (set[sets].anz_n)*sizeof(int)))==NULL)
9340 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9341 set[sets].node[n++]=surf[s].nod[k];
9342 }
9343 }
9344 for (k=0; k<surf[s].ne; k++)
9345 {
9346 if(e_enqire[surf[s].elem[k]].type)
9347 {
9348 set[sets].anz_e++;
9349 if((set[sets].elem=(int *)realloc((int *)set[sets].elem, (set[sets].anz_e)*sizeof(int)))==NULL)
9350 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9351 set[sets].elem[e++]=surf[s].elem[k];
9352 }
9353 }
9354 }
9355 }
9356 }
9357 if ( set[sets].anz_b>0)
9358 {
9359 for (i=0; i<set[sets].anz_b; i++)
9360 {
9361 b=set[sets].body[i];
9362 if(body[b].name != (char *)NULL)
9363 {
9364 for (k=0; k<body[b].nn; k++)
9365 {
9366 if(node[body[b].nod[k]].pflag!=-1 )
9367 {
9368 set[sets].anz_n++;
9369 if((set[sets].node=(int *)realloc((int *)set[sets].node, (set[sets].anz_n)*sizeof(int)))==NULL)
9370 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9371 set[sets].node[n++]=body[b].nod[k];
9372 }
9373 }
9374 for (k=0; k<body[b].ne; k++)
9375 {
9376 if(e_enqire[body[b].elem[k]].type)
9377 {
9378 set[sets].anz_e++;
9379 if((set[sets].elem=(int *)realloc((int *)set[sets].elem, (set[sets].anz_e)*sizeof(int)))==NULL)
9380 { printf("\nERROR: realloc failure in meshSet\n\n"); return(0); }
9381 set[sets].elem[e++]=body[b].elem[k];
9382 }
9383 }
9384 }
9385 }
9386 }
9387 qsort( set[sets].node, set[sets].anz_n, sizeof(int), (void *)compareInt );
9388 qsort( set[sets].elem, set[sets].anz_e, sizeof(int), (void *)compareInt );
9389
9390 /* erase multiple entities */
9391 if(set[sets].anz_n)
9392 {
9393 n=0;
9394 for(j=1; j<set[sets].anz_n; j++)
9395 {
9396 if(set[sets].node[n]!=set[sets].node[j]) set[sets].node[++n]=set[sets].node[j];
9397 }
9398 set[sets].anz_n=n+1;
9399 }
9400 if(set[sets].anz_e)
9401 {
9402 n=0;
9403 for(j=1; j<set[sets].anz_e; j++)
9404 {
9405 if(set[sets].elem[n]!=set[sets].elem[j]) set[sets].elem[++n]=set[sets].elem[j];
9406 }
9407 set[sets].anz_e=n+1;
9408 }
9409 nextSet:;
9410 }
9411
9412 for(i=0; i<apre->nmax; i++) free(nbuf[i]);
9413 free(nbuf);
9414 nbuf=NULL;
9415
9416 free(npre);
9417 npre=NULL;
9418 apre->n=0;
9419 apre->nmax=0;
9420 apre->nmin=MAX_INTEGER;
9421
9422
9423 /* for drawing purposes it is nessesary to add additional nodes */
9424 anz->orignmax = anz->nmax;
9425 anz->orign = anz->n;
9426
9427 if(anz->e)
9428 {
9429 e_enqire[0].type=0;
9430 }
9431
9432 // add the old node references
9433 if ( set[setNr].anz_p>0)
9434 {
9435 for(i=0; i<set[setNr].anz_p; i++)
9436 {
9437 p=set[setNr].pnt[i];
9438 if(pointnods[i])
9439 {
9440 if ((point[p].nod = (int *)realloc( (int *)point[p].nod, (point[p].nn+pointnods[i])*sizeof(int)) ) == NULL )
9441 { printf(" ERROR: realloc failure\n\n"); }
9442 for(j=0; j<pointnods[i]; j++) { point[p].nod[j+point[p].nn]=pointnod[i][j]; }
9443 point[p].nn+=pointnods[i];
9444 free(pointnod[i]);
9445 }
9446 }
9447 free(pointnod);
9448 free(pointnods);
9449 }
9450 if ( set[setNr].anz_l>0)
9451 {
9452 for(i=0; i<set[setNr].anz_l; i++)
9453 {
9454 p=set[setNr].line[i];
9455 if(linenods[i])
9456 {
9457 if ((line[p].nod = (int *)realloc( (int *)line[p].nod, (line[p].nn+linenods[i])*sizeof(int)) ) == NULL )
9458 { printf(" ERROR: realloc failure\n\n"); }
9459 for(j=0; j<linenods[i]; j++) { line[p].nod[j+line[p].nn]=linenod[i][j]; }
9460 line[p].nn+=linenods[i];
9461 free(linenod[i]);
9462 }
9463 if(lineelems[i])
9464 {
9465 if ((line[p].elem = (int *)realloc( (int *)line[p].elem, (line[p].ne+lineelems[i])*sizeof(int)) ) == NULL )
9466 { printf(" ERROR: realloc failure\n\n"); }
9467 for(j=0; j<lineelems[i]; j++) { line[p].elem[j+line[p].ne]=lineelem[i][j]; }
9468 line[p].ne+=lineelems[i];
9469 free(lineelem[i]);
9470 }
9471 }
9472 free(linenod);
9473 free(linenods);
9474 free(lineelem);
9475 free(lineelems);
9476 }
9477 if ( set[setNr].anz_s>0)
9478 {
9479 for(i=0; i<set[setNr].anz_s; i++)
9480 {
9481 p=set[setNr].surf[i];
9482 if(surfnods[i])
9483 {
9484 if ((surf[p].nod = (int *)realloc( (int *)surf[p].nod, (surf[p].nn+surfnods[i])*sizeof(int)) ) == NULL )
9485 { printf(" ERROR: realloc failure\n\n"); }
9486 for(j=0; j<surfnods[i]; j++) { surf[p].nod[j+surf[p].nn]=surfnod[i][j]; }
9487 surf[p].nn+=surfnods[i];
9488 free(surfnod[i]);
9489 }
9490 if(surfelems[i])
9491 {
9492 if ((surf[p].elem = (int *)realloc( (int *)surf[p].elem, (surf[p].ne+surfelems[i])*sizeof(int)) ) == NULL )
9493 { printf(" ERROR: realloc failure\n\n"); }
9494 for(j=0; j<surfelems[i]; j++) { surf[p].elem[j+surf[p].ne]=surfelem[i][j]; }
9495 surf[p].ne+=surfelems[i];
9496 free(surfelem[i]);
9497 }
9498 }
9499 free(surfnod);
9500 free(surfnods);
9501 free(surfelem);
9502 free(surfelems);
9503 }
9504 if ( set[setNr].anz_b>0)
9505 {
9506 for(i=0; i<set[setNr].anz_b; i++)
9507 {
9508 p=set[setNr].body[i];
9509 if(bodynods[i])
9510 {
9511 if ((body[p].nod = (int *)realloc( (int *)body[p].nod, (body[p].nn+bodynods[i])*sizeof(int)) ) == NULL )
9512 { printf(" ERROR: realloc failure\n\n"); }
9513 for(j=0; j<bodynods[i]; j++) { body[p].nod[j+body[p].nn]=bodynod[i][j]; }
9514 body[p].nn+=bodynods[i];
9515 free(bodynod[i]);
9516 }
9517 if(bodyelems[i])
9518 {
9519 if ((body[p].elem = (int *)realloc( (int *)body[p].elem, (body[p].ne+bodyelems[i])*sizeof(int)) ) == NULL )
9520 { printf(" ERROR: realloc failure\n\n"); }
9521 for(j=0; j<bodyelems[i]; j++) { body[p].elem[j+body[p].ne]=bodyelem[i][j]; }
9522 body[p].ne+=bodyelems[i];
9523 free(bodyelem[i]);
9524 }
9525 }
9526 free(bodynod);
9527 free(bodynods);
9528 free(bodyelem);
9529 free(bodyelems);
9530 }
9531
9532 if(printFlag) printf(" end of meshSet\n");
9533 return(1);
9534 }
9535