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 /*
24 TODO:
25 sendSliders() and sendSurfNormalen(): still working on node basis instead of using the faces
26 */
27
28
29
30 #include <cgx.h>
31
32 #define TEST 0 /* debugging */
33
34 #define DOFX 1
35 #define DOFY 2
36 #define DOFZ 3
37 #define DOFT 11
38 #define DOFP 8
39 #define MIN_VECTOR 0.0001
40
41 extern char datin[MAX_LINE_LENGTH]; /* Input-data-file */
42
43 extern int neqn; /* offset der equations fuer ansys, bzw. MPC ID fuer Nast. */
44
45 extern int basCol[3]; /* color indexes due to basic colormap */
46 extern int width_ini, height_ini; /* Grafig-Fensterbreite/hoehe */
47 extern int width_menu, height_menu;
48 extern int w0, w1, w_index, w_rgb, activWindow;
49 extern int width_w0, height_w0;
50 extern int width_w1, height_w1;
51 extern int MouseMode; /* status maustasten */
52 extern double dtx, dty, drx, dry, drz, ds; /* Verschiebungen */
53 extern GLdouble R[4][4]; /* Rotationsmatrix */
54 extern char surfFlag; /* zeichne nur Oberflaechenelemente (1), sonst (0)*/
55 extern char modelEdgeFlag; /* zeichne mit Modell-Ecken (1), sonst (0)*/
56 extern char frameFlag; /* mit (1) oder ohne Rahmen um das Grafigfenster */
57 extern double dx ,dy; /* Mauskoordinaten */
58 extern int steps; /* Schrittweite der Farbscala, und NURB aufloesung */
59
60 extern Scale scale[1];
61 extern Summen anz[1];
62 extern Edges *edge;
63 extern Nodes *node;
64 extern Elements *e_enqire;
65 extern Datasets *lcase;
66 extern Faces *face;
67
68 extern Alias *alias;
69 extern Sets *set;
70 extern Points *point;
71 extern Lines *line;
72 extern Lcmb *lcmb;
73 extern Gsur *surf;
74 extern Gbod *body;
75 extern Nurbs *nurbs;
76 extern SumGeo anzGeo[1];
77
78 extern int offset;
79
80 /* for CFD-meshing */
81 extern int anz_cfdSurfs;
82
83
84 /* Set Management */
85 extern char printFlag; /* printf 1:on 0:off */
86
87 /* the copied node-sets which have to be filled with values from new loaded Datasets */
88 extern CopiedNodeSets copiedNodeSets[1];
89
90 extern char **parameter;
91
92
93 /* search all surfaces who are fully described by the selected nodes and add them to the set */
compSurfElems(int setNr,Elements ** ptr)94 int compSurfElems( int setNr, Elements **ptr)
95 {
96 int i, j, k, n=0, elem2nr=0, anz_n;
97 int *surnod=NULL;
98 Elements *elem2;
99
100 elem2=*ptr;
101
102 /* mark the surface nodes for easy element identification */
103 if( (surnod=(int *)realloc((int *)surnod, (anz->nmax+1)*sizeof(int) ) )==NULL)
104 { printf(" ERROR: malloc failure\n"); return(0); }
105 for (i=0; i<=anz->nmax; i++) surnod[i]=0;
106 for (i=0; i<set[setNr].anz_n; i++) surnod[set[setNr].node[i]]=1;
107
108
109 for(i=0; i<anz->f; i++)
110 {
111 anz_n=n=0;
112 if (face[i].type==7) anz_n=3;
113 if (face[i].type==8) anz_n=6;
114 if (face[i].type==9) anz_n=4;
115 if (face[i].type==10) anz_n=8;
116
117 if(anz_n)
118 {
119 for (k=0; k<anz_n; k++) if (surnod[face[i].nod[k]]) n++;
120 if (n==anz_n)
121 {
122 if ( (elem2 = (Elements *)realloc((Elements *)elem2, (elem2nr+1) * sizeof(Elements))) == NULL )
123 { printf("\n\nERROR: malloc failed in compSurfElems\n\n"); return(0); }
124 seta( setNr, "e", face[i].elem_nr);
125 elem2[elem2nr].nr = elem2nr+1+anz->emax;
126 elem2[elem2nr].type = face[i].type;
127 elem2[elem2nr].group = face[i].nr;
128
129 for (j=0; j<anz_n; j++)
130 {
131 elem2[elem2nr].nod[j]=face[i].nod[j];
132 }
133 elem2nr++;
134 }
135 else if(n>anz_n)
136 {
137 printf("ERROR: to much corners found on elem:%d\n", face[i].elem_nr);
138 }
139 }
140 }
141
142
143 *ptr=elem2;
144 free(surnod);
145 return( elem2nr );
146 }
147
148
149 typedef struct {
150 int nod[4];
151 double ncol[4][3];
152 int elem_nr;
153 int group;
154 int mat;
155 } CQuad4;
156
157 typedef struct {
158 double side[48][3]; /* side[Nr.][x|y|z] */
159 } Normalen;
160
161
calcNormale_quad4(int i,int n1,int n2,int n3,int n4,int f,Nodes * node,Normalen * norm)162 void calcNormale_quad4(int i, int n1, int n2, int n3, int n4, int f, Nodes *node, Normalen *norm)
163 {
164 static double v1[3], v2[3], v3[3];
165
166 /* Vereinfachte Normale auf Flaeche des i.Elements*/
167 v_result( &node[n1].nx, &node[n3].nx, v1);
168 v_result( &node[n2].nx, &node[n4].nx, v2);
169 v_prod( v1, v2, v3 );
170 v_norm( v3, norm[i].side[f] );
171
172 }
173
getCQuad4Normalen(CQuad4 * cquad4,Nodes * node,int * num_etype,Normalen * norm)174 void getCQuad4Normalen( CQuad4 *cquad4, Nodes *node, int *num_etype, Normalen *norm )
175 {
176 int i;
177
178 for (i=0; i<*num_etype; i++ )
179 {
180 calcNormale_quad4(i,cquad4[i].nod[0], cquad4[i].nod[1], cquad4[i].nod[2],
181 cquad4[i].nod[3], 0, node, norm);
182 }
183 }
184
185
sendSurfNormalen(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,Datasets * lcase,Scale * scale)186 void sendSurfNormalen( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire,
187 Datasets *lcase , Scale *scale )
188 {
189 int setNr, i, j, n=0, ipuf, elem2nr=0, comp, faces;
190 char prognam[MAX_LINE_LENGTH];
191 static int *isort=NULL;
192 Summen anz2[1];
193 static Nodes *node2=NULL;
194 static Elements *elem2=NULL;
195 static Datasets *lcase2=NULL;
196 static CQuad4 *face4=NULL;
197 static Normalen *norm2=NULL;
198 extern int compareInt();
199
200 strcpy ( prognam, setname);
201 setNr=getSetNr(setname);
202 if (setNr<0)
203 {
204 printf (" ERROR: set:%s does not exist\n", setname);
205 return;
206 }
207
208 /* search all element-faces who are fully described by the selected nodes and add them to the set */
209 printf("Please wait\n");
210 elem2nr=compSurfElems( setNr, &elem2);
211
212 /* calculate the normals on the new faces */
213 faces=0;
214 if ( (face4 = (CQuad4 *)malloc( (elem2nr+1) * sizeof(CQuad4))) == NULL )
215 printf("\n\nERROR: malloc failed\n\n") ;
216 for (i=0; i<elem2nr; i++ )
217 {
218 if(elem2[i].type==9)
219 {
220 for (n=0; n<4; n++)
221 {
222 face4[faces].nod[n]=elem2[i].nod[n];
223 }
224 face4[faces].elem_nr = elem2[i].nr;
225 face4[faces].group = elem2[i].group;
226 face4[faces].mat = elem2[i].mat;
227 faces++;
228 }
229 }
230
231 if(faces>0)
232 {
233 anz2->l = 1;
234 if ( (norm2 = (Normalen *)malloc( (faces+1)*4 * sizeof(Normalen))) == NULL )
235 printf("\n\nERROR: malloc failed in sendSurfNormalen\n\n") ;
236 getCQuad4Normalen( face4, node, &faces, norm2);
237
238 /* send the surfs and normals in the frd format */
239 if ( (lcase2 = (Datasets *)malloc( 2 * sizeof(Datasets))) == NULL )
240 printf("\n\n ERROR: malloc failed lcase2\n\n") ;
241
242 sprintf( lcase2[0].name,"NORM");
243 comp=0;
244 lcase2[0].ncomps=3;
245 lcase2[0].irtype=3;
246 lcase2[0].npheader=0;
247 if ( (lcase2[0].nmax = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
248 printf("\n\n ERROR: malloc failure\n\n" );
249 if ( (lcase2[0].nmin = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
250 printf("\n\n ERROR: malloc failure\n\n" );
251 if ( (lcase2[0].max = (float *)malloc(lcase2[0].ncomps * sizeof(float))) == NULL )
252 printf("\n\n ERROR: malloc failure\n\n" );
253 if ( (lcase2[0].min = (float *)malloc(lcase2[0].ncomps * sizeof(float))) == NULL )
254 printf("\n\n ERROR: malloc failure\n\n" );
255 if ( (lcase2[0].compName = (char **)malloc(lcase2[0].ncomps * sizeof(char *))) == NULL )
256 printf("\n\n ERROR: malloc failure\n\n" );
257 if ( (lcase2[0].icname = (char **)malloc(lcase2[0].ncomps * sizeof(char *))) == NULL )
258 printf("\n\n ERROR: malloc failure\n\n" );
259 if ( (lcase2[0].menu = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
260 printf("\n\n ERROR: malloc failure\n\n" );
261 if ( (lcase2[0].ictype = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
262 printf("\n\n ERROR: malloc failure\n\n" );
263 if ( (lcase2[0].icind1 = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
264 printf("\n\n ERROR: malloc failure\n\n" );
265 if ( (lcase2[0].icind2 = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
266 printf("\n\n ERROR: malloc failure\n\n" );
267 if ( (lcase2[0].iexist = (int *)malloc(lcase2[0].ncomps * sizeof(int))) == NULL )
268 printf("\n\n ERROR: malloc failure\n\n" );
269
270 for(i=comp; i<lcase2[0].ncomps; i++)
271 {
272 if ( (lcase2[0].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
273 printf("\n\n ERROR: malloc failed\n\n" );
274 if ( (lcase2[0].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
275 printf("\n\n ERROR: malloc failed\n\n" );
276 lcase2[0].max[i]=-MAX_INTEGER;
277 lcase2[0].min[i]=MAX_INTEGER;
278
279 lcase2[0].menu[i] = 1;
280 lcase2[0].ictype[i] = 2;
281 lcase2[0].icind1[i] = i+1;
282 lcase2[0].icind2[i] = 0;
283 lcase2[0].iexist[i] = 0;
284 }
285
286 strcpy ( lcase2[0].compName[0], "x ");
287 strcpy ( lcase2[0].compName[1], "y ");
288 strcpy ( lcase2[0].compName[2], "z ");
289
290 if ( (lcase2[0].edat = (float ***)malloc( (lcase2[0].ncomps)*sizeof(float **))) == NULL )
291 printf("\n\n ERROR: malloc failed esxx\n\n" );
292 if ( (lcase2[0].edat[0] = (float **)malloc( (elem2nr+anz->emax+1)*sizeof(float *))) == NULL )
293 printf("\n\n ERROR: malloc failed esxx\n\n" );
294 if ( (lcase2[0].edat[1] = (float **)malloc( (elem2nr+anz->emax+1)*sizeof(float *))) == NULL )
295 printf("\n\n ERROR: malloc failed esyy\n\n" );
296 if ( (lcase2[0].edat[2] = (float **)malloc( (elem2nr+anz->emax+1)*sizeof(float *))) == NULL )
297 printf("\n\n ERROR: malloc failed eszz\n\n" );
298
299 for (i=0; i<elem2nr; i++ )
300 {
301 for (j=0; j<lcase2[0].ncomps; j++)
302 {
303 if ( (lcase2[0].edat[j][elem2[i].nr] = (float *)malloc( (4) * sizeof(float))) == NULL )
304 printf("\n\n ERROR: malloc failed esxx[%d]\n\n", i );
305 }
306 }
307
308 for (i=0; i<faces; i++ )
309 {
310 for (j=0; j<4; j++)
311 {
312 lcase2[0].edat[0][face4[i].elem_nr][j]=norm2[i].side[0][0];
313 lcase2[0].edat[1][face4[i].elem_nr][j]=norm2[i].side[0][1];
314 lcase2[0].edat[2][face4[i].elem_nr][j]=norm2[i].side[0][2];
315 }
316 }
317 }
318 else anz2->l = 0;
319
320 anz2->emax=-MAX_INTEGER;
321 anz2->emin=MAX_INTEGER;
322 for (i=0; i<elem2nr; i++)
323 {
324 if (anz2->emax<elem2[i].nr ) anz2->emax = elem2[i].nr;
325 if (anz2->emin>elem2[i].nr ) anz2->emin = elem2[i].nr;
326 ipuf=0;
327 if (elem2[i].type == 1) ipuf = 8; /* CHEXA8 */
328 else if (elem2[i].type == 3) ipuf = 4; /* CTET4 */
329 else if (elem2[i].type == 4) ipuf = 20; /* CHEXA20 */
330 else if (elem2[i].type == 6) ipuf = 10; /* CTET10 */
331 else if (elem2[i].type == 7) ipuf = 3; /* CTRI3 */
332 else if (elem2[i].type == 8) ipuf = 6; /* CTRI6 */
333 else if (elem2[i].type == 9) ipuf = 4; /* CQUAD4 */
334 else if (elem2[i].type == 10) ipuf = 8; /* CQUAD8 */
335 else if (elem2[i].type == 11) ipuf = 2; /* CBEAM */
336 else if (elem2[i].type == 12) ipuf = 3; /* CBEAM3 */
337 else
338 {
339 if(printFlag) printf (" elem(%d) not a known type (%d)\n", elem2[i].nr, elem2[i].type);
340 }
341 for (j=0; j<ipuf; j++)
342 {
343 seta( setNr, "n", elem2[i].nod[j]);
344 }
345 }
346 /* nodes must follow the elements (seta n above!) */
347 /* sort the nodenumbers */
348 if ( (node2 = (Nodes *)malloc( (anz->nmax+1) * sizeof(Nodes))) == NULL )
349 printf("\n\nERROR: malloc failed\n\n") ;
350
351 anz2->nmax = anz2->nmin = 0;
352
353 if ( (isort = (int *)realloc( isort, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
354 printf("ERROR: realloc failed: isort\n\n" );
355 for( i=0; i<set[setNr].anz_n; i++) isort[i]=set[setNr].node[i];
356 qsort( isort, set[setNr].anz_n, sizeof(int), (void *)compareInt );
357
358 for (i=0; i<set[setNr].anz_n; i++)
359 {
360 node2[i].nr = isort[i];
361 node2[isort[i]].nx = node[isort[i]].nx;
362 node2[isort[i]].ny = node[isort[i]].ny;
363 node2[isort[i]].nz = node[isort[i]].nz;
364 if (anz2->nmax<node2[i].nr) anz2->nmax = node2[i].nr;
365 if (anz2->nmin>node2[i].nr) anz2->nmin = node2[i].nr;
366 }
367 strcpy( anz2->model, setname);
368 anz2->n = set[setNr].anz_n;
369 anz2->e = elem2nr;
370 anz2->u = 0;
371 anz2->p = 0;
372
373 descalNodes ( set[setNr].anz_n, node2, scale);
374 write2frd( "surface.frd", anz2, node2, elem2, lcase2, 0);
375 scalNodes ( set[setNr].anz_n, node2, scale );
376
377 /* free temporary memory */
378 if(faces)
379 {
380 for (i=0; i<lcase2[0].ncomps; i++)
381 {
382 for(j=0; j<elem2nr; j++)
383 {
384 free(lcase2[0].edat[i][elem2[j].nr]);
385 lcase2[0].edat[i][elem2[j].nr]=NULL;
386 }
387 free(lcase2[0].edat[i]);
388 lcase2[0].edat[i]=NULL;
389 }
390 free(lcase2);
391 lcase2=NULL;
392 }
393 free(node2);
394 free(face4);
395 free(elem2);
396 free(norm2);
397 node2=NULL;
398 face4=NULL;
399 elem2=NULL;
400 norm2=NULL;
401
402 printf (" ready\n");
403 }
404
405
406
getNodeNormalen(int ** sum_n_ptr,Nodes ** norm_ptr,int setNr,Summen * anz,Faces * face)407 void getNodeNormalen(int **sum_n_ptr, Nodes **norm_ptr, int setNr, Summen *anz, Faces *face)
408 {
409 int i,f, n,k;
410 int *sum_n=NULL;
411 Nodes *norm=NULL;
412
413 if ( (norm = (Nodes *)realloc( (Nodes *)norm, (anz->nmax+1) * sizeof(Nodes))) == NULL )
414 {
415 printf("WARNING: realloc failed in sendSet\n");
416 return;
417 }
418 if ( (sum_n = (int *)realloc( (int *)sum_n, (anz->nmax+1) * sizeof(int))) == NULL )
419 {
420 printf("WARNING: realloc failed in sendSet\n");
421 return;
422 }
423
424 /* ini all = 0 */
425 for (n=0; n<=anz->nmax; n++ )
426 {
427 sum_n[n]=0;
428 norm[n].nx=norm[n].ny=norm[n].nz=0.;
429 }
430
431 /* - add the normals per node */
432 for (k=0; k<set[setNr].anz_f; k++ )
433 {
434 f=set[setNr].face[k];
435 switch(face[f].type)
436 {
437 case 7:
438 for(n=0; n<3; n++)
439 {
440 norm[face[f].nod[n]].nx+=face[f].side[0][0];
441 norm[face[f].nod[n]].ny+=face[f].side[0][1];
442 norm[face[f].nod[n]].nz+=face[f].side[0][2];
443 sum_n[face[f].nod[n]]++;
444 }
445 break;
446 case 8:
447 i=0;
448 norm[face[f].nod[i]].nx+=face[f].side[0][0];
449 norm[face[f].nod[i]].ny+=face[f].side[0][1];
450 norm[face[f].nod[i]].nz+=face[f].side[0][2];
451 sum_n[face[f].nod[i]]++;
452 i=3;
453 norm[face[f].nod[i]].nx+=face[f].side[0][0];
454 norm[face[f].nod[i]].ny+=face[f].side[0][1];
455 norm[face[f].nod[i]].nz+=face[f].side[0][2];
456 sum_n[face[f].nod[i]]++;
457 i=5;
458 norm[face[f].nod[i]].nx+=face[f].side[0][0];
459 norm[face[f].nod[i]].ny+=face[f].side[0][1];
460 norm[face[f].nod[i]].nz+=face[f].side[0][2];
461 sum_n[face[f].nod[i]]++;
462 i=2;
463 norm[face[f].nod[i]].nx+=face[f].side[1][0];
464 norm[face[f].nod[i]].ny+=face[f].side[1][1];
465 norm[face[f].nod[i]].nz+=face[f].side[1][2];
466 sum_n[face[f].nod[i]]++;
467 i=5;
468 norm[face[f].nod[i]].nx+=face[f].side[1][0];
469 norm[face[f].nod[i]].ny+=face[f].side[1][1];
470 norm[face[f].nod[i]].nz+=face[f].side[1][2];
471 sum_n[face[f].nod[i]]++;
472 i=4;
473 norm[face[f].nod[i]].nx+=face[f].side[1][0];
474 norm[face[f].nod[i]].ny+=face[f].side[1][1];
475 norm[face[f].nod[i]].nz+=face[f].side[1][2];
476 sum_n[face[f].nod[i]]++;
477 i=4;
478 norm[face[f].nod[i]].nx+=face[f].side[2][0];
479 norm[face[f].nod[i]].ny+=face[f].side[2][1];
480 norm[face[f].nod[i]].nz+=face[f].side[2][2];
481 sum_n[face[f].nod[i]]++;
482 i=5;
483 norm[face[f].nod[i]].nx+=face[f].side[2][0];
484 norm[face[f].nod[i]].ny+=face[f].side[2][1];
485 norm[face[f].nod[i]].nz+=face[f].side[2][2];
486 sum_n[face[f].nod[i]]++;
487 i=3;
488 norm[face[f].nod[i]].nx+=face[f].side[2][0];
489 norm[face[f].nod[i]].ny+=face[f].side[2][1];
490 norm[face[f].nod[i]].nz+=face[f].side[2][2];
491 sum_n[face[f].nod[i]]++;
492 i=3;
493 norm[face[f].nod[i]].nx+=face[f].side[3][0];
494 norm[face[f].nod[i]].ny+=face[f].side[3][1];
495 norm[face[f].nod[i]].nz+=face[f].side[3][2];
496 sum_n[face[f].nod[i]]++;
497 i=1;
498 norm[face[f].nod[i]].nx+=face[f].side[3][0];
499 norm[face[f].nod[i]].ny+=face[f].side[3][1];
500 norm[face[f].nod[i]].nz+=face[f].side[3][2];
501 sum_n[face[f].nod[i]]++;
502 i=4;
503 norm[face[f].nod[i]].nx+=face[f].side[3][0];
504 norm[face[f].nod[i]].ny+=face[f].side[3][1];
505 norm[face[f].nod[i]].nz+=face[f].side[3][2];
506 sum_n[face[f].nod[i]]++;
507 break;
508 case 9:
509 for(n=0; n<4; n++)
510 {
511 norm[face[f].nod[n]].nx+=face[f].side[0][0];
512 norm[face[f].nod[n]].ny+=face[f].side[0][1];
513 norm[face[f].nod[n]].nz+=face[f].side[0][2];
514 sum_n[face[f].nod[n]]++;
515 }
516 break;
517 case 10:
518 i=0;
519 norm[face[f].nod[i]].nx+=face[f].side[0][0];
520 norm[face[f].nod[i]].ny+=face[f].side[0][1];
521 norm[face[f].nod[i]].nz+=face[f].side[0][2];
522 sum_n[face[f].nod[i]]++;
523 i=4;
524 norm[face[f].nod[i]].nx+=face[f].side[0][0];
525 norm[face[f].nod[i]].ny+=face[f].side[0][1];
526 norm[face[f].nod[i]].nz+=face[f].side[0][2];
527 sum_n[face[f].nod[i]]++;
528 i=4;
529 norm[face[f].nod[i]].nx+=face[f].side[1][0];
530 norm[face[f].nod[i]].ny+=face[f].side[1][1];
531 norm[face[f].nod[i]].nz+=face[f].side[1][2];
532 sum_n[face[f].nod[i]]++;
533 i=1;
534 norm[face[f].nod[i]].nx+=face[f].side[1][0];
535 norm[face[f].nod[i]].ny+=face[f].side[1][1];
536 norm[face[f].nod[i]].nz+=face[f].side[1][2];
537 sum_n[face[f].nod[i]]++;
538 i=1;
539 norm[face[f].nod[i]].nx+=face[f].side[2][0];
540 norm[face[f].nod[i]].ny+=face[f].side[2][1];
541 norm[face[f].nod[i]].nz+=face[f].side[2][2];
542 sum_n[face[f].nod[i]]++;
543 i=5;
544 norm[face[f].nod[i]].nx+=face[f].side[2][0];
545 norm[face[f].nod[i]].ny+=face[f].side[2][1];
546 norm[face[f].nod[i]].nz+=face[f].side[2][2];
547 sum_n[face[f].nod[i]]++;
548 i=5;
549 norm[face[f].nod[i]].nx+=face[f].side[3][0];
550 norm[face[f].nod[i]].ny+=face[f].side[3][1];
551 norm[face[f].nod[i]].nz+=face[f].side[3][2];
552 sum_n[face[f].nod[i]]++;
553 i=2;
554 norm[face[f].nod[i]].nx+=face[f].side[3][0];
555 norm[face[f].nod[i]].ny+=face[f].side[3][1];
556 norm[face[f].nod[i]].nz+=face[f].side[3][2];
557 sum_n[face[f].nod[i]]++;
558 i=2;
559 norm[face[f].nod[i]].nx+=face[f].side[4][0];
560 norm[face[f].nod[i]].ny+=face[f].side[4][1];
561 norm[face[f].nod[i]].nz+=face[f].side[4][2];
562 sum_n[face[f].nod[i]]++;
563 i=6;
564 norm[face[f].nod[i]].nx+=face[f].side[4][0];
565 norm[face[f].nod[i]].ny+=face[f].side[4][1];
566 norm[face[f].nod[i]].nz+=face[f].side[4][2];
567 sum_n[face[f].nod[i]]++;
568 i=6;
569 norm[face[f].nod[i]].nx+=face[f].side[5][0];
570 norm[face[f].nod[i]].ny+=face[f].side[5][1];
571 norm[face[f].nod[i]].nz+=face[f].side[5][2];
572 sum_n[face[f].nod[i]]++;
573 i=3;
574 norm[face[f].nod[i]].nx+=face[f].side[5][0];
575 norm[face[f].nod[i]].ny+=face[f].side[5][1];
576 norm[face[f].nod[i]].nz+=face[f].side[5][2];
577 sum_n[face[f].nod[i]]++;
578 i=3;
579 norm[face[f].nod[i]].nx+=face[f].side[6][0];
580 norm[face[f].nod[i]].ny+=face[f].side[6][1];
581 norm[face[f].nod[i]].nz+=face[f].side[6][2];
582 sum_n[face[f].nod[i]]++;
583 i=7;
584 norm[face[f].nod[i]].nx+=face[f].side[6][0];
585 norm[face[f].nod[i]].ny+=face[f].side[6][1];
586 norm[face[f].nod[i]].nz+=face[f].side[6][2];
587 sum_n[face[f].nod[i]]++;
588 i=7;
589 norm[face[f].nod[i]].nx+=face[f].side[7][0];
590 norm[face[f].nod[i]].ny+=face[f].side[7][1];
591 norm[face[f].nod[i]].nz+=face[f].side[7][2];
592 sum_n[face[f].nod[i]]++;
593 i=0;
594 norm[face[f].nod[i]].nx+=face[f].side[7][0];
595 norm[face[f].nod[i]].ny+=face[f].side[7][1];
596 norm[face[f].nod[i]].nz+=face[f].side[7][2];
597 sum_n[face[f].nod[i]]++;
598 break;
599 }
600 }
601
602 for (n=0; n<=anz->nmax; n++ )
603 {
604 if( sum_n[n] >0 )
605 {
606 v_norm( &norm[n].nx, &norm[n].nx );
607 //printf("sum:%d node:%d norm: %lf %lf %lf l:%lf \n", sum_n[n], n, norm[n].nx, norm[n].ny, norm[n].nz, sqrt(norm[n].nx*norm[n].nx+norm[n].ny*norm[n].ny+norm[n].nz*norm[n].nz));
608 }
609 }
610
611 *sum_n_ptr = sum_n;
612 *norm_ptr = norm;
613 }
614
615
616
sendSlidersf(char * setname,char * format,char * spcType)617 void sendSlidersf( char *setname, char *format, char *spcType )
618 {
619 int setNr;
620 int length, k,f,n;
621 char prognam[MAX_LINE_LENGTH];
622
623 double xx,yy,zz;
624 Nodes *norm; // stores the face normale
625
626
627 FILE *handle;
628
629
630 strcpy ( prognam, setname);
631 length= strlen ( setname );
632 setNr=getSetNr(setname);
633 if (setNr<0)
634 {
635 printf (" ERROR: set:%s does not exist\n", setname);
636 return;
637 }
638 strcpy(&prognam[length],".equf");
639
640 /* ---- sliders ----- */
641 if(!set[setNr].anz_f)
642 {
643 printf(" WARNING: Found no faces in set:%s\n",set[setNr].name);
644 return;
645 }
646
647 strcpy(parameter[0], prognam);
648 write2stack(1, parameter);
649
650 if( compare(spcType, "s", 1) == 1)
651 {
652 /* faces slide on their element surfaces */
653
654 /* calculate the average normal on every node */
655 // known, just average over all triangles of the face if necessary. face[f].side[0-7][0-2];
656 if ( (norm = (Nodes *)malloc((set[setNr].anz_f+1) * sizeof(Nodes))) == NULL )
657 {
658 printf("WARNING: realloc failed in sendSet\n");
659 return;
660 }
661 for (k=0; k<set[setNr].anz_f; k++ )
662 {
663 f=set[setNr].face[k];
664 switch(face[f].type)
665 {
666 case 7:
667 for(n=0; n<3; n++)
668 {
669 norm[k].nx=face[f].side[0][0];
670 norm[k].ny=face[f].side[0][1];
671 norm[k].nz=face[f].side[0][2];
672 }
673 break;
674 case 8:
675 norm[k].nx=face[f].side[0][0];
676 norm[k].ny=face[f].side[0][1];
677 norm[k].nz=face[f].side[0][2];
678 norm[k].nx+=face[f].side[1][0];
679 norm[k].ny+=face[f].side[1][1];
680 norm[k].nz+=face[f].side[1][2];
681 norm[k].nx+=face[f].side[2][0];
682 norm[k].ny+=face[f].side[2][1];
683 norm[k].nz+=face[f].side[2][2];
684 norm[k].nx+=face[f].side[3][0];
685 norm[k].ny+=face[f].side[3][1];
686 norm[k].nz+=face[f].side[3][2];
687 break;
688 case 9:
689 norm[k].nx=face[f].side[0][0];
690 norm[k].ny=face[f].side[0][1];
691 norm[k].nz=face[f].side[0][2];
692 break;
693 case 10:
694 norm[k].nx=face[f].side[0][0];
695 norm[k].ny=face[f].side[0][1];
696 norm[k].nz=face[f].side[0][2];
697 norm[k].nx+=face[f].side[1][0];
698 norm[k].ny+=face[f].side[1][1];
699 norm[k].nz+=face[f].side[1][2];
700 norm[k].nx+=face[f].side[2][0];
701 norm[k].ny+=face[f].side[2][1];
702 norm[k].nz+=face[f].side[2][2];
703 norm[k].nx+=face[f].side[3][0];
704 norm[k].ny+=face[f].side[3][1];
705 norm[k].nz+=face[f].side[3][2];
706 norm[k].nx+=face[f].side[4][0];
707 norm[k].ny+=face[f].side[4][1];
708 norm[k].nz+=face[f].side[4][2];
709 norm[k].nx+=face[f].side[5][0];
710 norm[k].ny+=face[f].side[5][1];
711 norm[k].nz+=face[f].side[5][2];
712 norm[k].nx+=face[f].side[6][0];
713 norm[k].ny+=face[f].side[6][1];
714 norm[k].nz+=face[f].side[6][2];
715 norm[k].nx+=face[f].side[7][0];
716 norm[k].ny+=face[f].side[7][1];
717 norm[k].nz+=face[f].side[7][2];
718 break;
719 }
720 v_norm( &norm[k].nx, &norm[k].nx );
721 }
722 }
723 else
724 {
725 errMsg ("\nERROR: format:%s not known\n", spcType);
726 return;
727 }
728
729 /* write the sliders in abaqus-format */
730 if (compare( format, "abq", 3)== 3)
731 {
732 handle = fopen (prognam, "w");
733 if ( handle== NULL )
734 {
735 printf ("\nThe input file %s could not be opened.\n\n", prognam);
736 return;
737 }
738 fprintf(handle, "** Sliders based on %s\n", setname);
739 for (k=0; k<set[setNr].anz_f; k++ )
740 {
741 f=set[setNr].face[k];
742 printf("elem %d face %d Norm:%lf %lf %lf\n"
743 , face[f].elem_nr, face[f].nr+1
744 , norm[k].nx, norm[k].ny, norm[k].nz );
745
746 xx=norm[k].nx*norm[k].nx;
747 yy=norm[k].ny*norm[k].ny;
748 zz=norm[k].nz*norm[k].nz;
749 if((xx>MIN_VECTOR)
750 &&(yy>MIN_VECTOR)&&(zz>MIN_VECTOR))
751 {
752 fprintf(handle, "*EQUATIONF\n");
753 fprintf(handle, "%d\n", 3);
754 fprintf(handle, "%d,S%d,%d,%lf, %d,S%d,%d,%lf, %d,S%d,%d,%lf \n"
755 , face[f].elem_nr, face[f].nr+1, DOFX, norm[k].nx
756 , face[f].elem_nr, face[f].nr+1, DOFY, norm[k].ny
757 , face[f].elem_nr, face[f].nr+1, DOFZ, norm[k].nz );
758 }
759 else if((xx<=MIN_VECTOR)
760 &&(yy>MIN_VECTOR)&&(zz>MIN_VECTOR))
761 {
762 fprintf(handle, "*EQUATIONF\n");
763 fprintf(handle, "%d\n", 2);
764 fprintf(handle, "%d,S%d,%d,%lf, %d,S%d,%d,%lf \n"
765 , face[f].elem_nr, face[f].nr+1, DOFY, norm[k].ny
766 , face[f].elem_nr, face[f].nr+1, DOFZ, norm[k].nz );
767 }
768 else if((yy<=MIN_VECTOR)
769 &&(xx>MIN_VECTOR)&&(zz>MIN_VECTOR))
770 {
771 fprintf(handle, "*EQUATIONF\n");
772 fprintf(handle, "%d\n", 2);
773 fprintf(handle, "%d,S%d,%d,%lf, %d,S%d,%d,%lf \n"
774 , face[f].elem_nr, face[f].nr+1, DOFX, norm[k].nx
775 , face[f].elem_nr, face[f].nr+1, DOFZ, norm[k].nz );
776 }
777 else if((zz<=MIN_VECTOR)
778 &&(xx>MIN_VECTOR)&&(yy>MIN_VECTOR))
779 {
780 fprintf(handle, "*EQUATIONF\n");
781 fprintf(handle, "%d\n", 2);
782 fprintf(handle, "%d,S%d,%d,%lf, %d,S%d,%d,%lf \n"
783 , face[f].elem_nr, face[f].nr+1, DOFX, norm[k].nx
784 , face[f].elem_nr, face[f].nr+1, DOFY, norm[k].ny );
785 }
786
787 else if((xx>MIN_VECTOR)
788 &&(yy<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
789 {
790 fprintf(handle, "*BOUNDARYF\n");
791 fprintf(handle, "%d,S%d,%d,,0. \n"
792 , face[f].elem_nr, face[f].nr+1, DOFX );
793 }
794 else if((yy>MIN_VECTOR)
795 &&(xx<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
796 {
797 fprintf(handle, "*BOUNDARYF\n");
798 fprintf(handle, "%d,S%d,%d,,0. \n"
799 , face[f].elem_nr, face[f].nr+1, DOFY );
800 }
801 else if((zz>MIN_VECTOR)
802 &&(xx<=MIN_VECTOR)&&(yy<=MIN_VECTOR))
803 {
804 fprintf(handle, "*BOUNDARYF\n");
805 fprintf(handle, "%d,S%d,%d,,0. \n"
806 , face[f].elem_nr, face[f].nr+1, DOFZ );
807 }
808 else printf("ERROR; no slider created for node:%d, S%d\n", face[f].elem_nr, face[f].nr+1);
809 }
810 fclose(handle);
811 }
812 else
813 {
814 errMsg(" ERROR: format %s not yet supported\n", format );
815 }
816
817 free(norm);
818
819 printf (" ready\n");
820 }
821
822
823
sendSliders(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * spcType)824 void sendSliders( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *spcType )
825 {
826 int setNr;
827 int length, i,n, anz_n;
828 char prognam[MAX_LINE_LENGTH];
829
830 double xx,yy,zz;
831 Nodes *norm;
832 int *sum_n=NULL, *buf_n=NULL;
833
834
835 int n0, n1, n2;
836 double p0[3], p1[3], p2[3], p3[3], N[3], p0p1[3], p0p2[3];
837
838 FILE *handle;
839
840
841 strcpy ( prognam, setname);
842 length= strlen ( setname );
843 setNr=getSetNr(setname);
844 if (setNr<0)
845 {
846 printf (" ERROR: set:%s does not exist\n", setname);
847 return;
848 }
849
850 /* cycsym sliding-mpcs */
851 /* the nodes slide on copies of them. This copy-nodes can be used for cycsym or spc etc. */
852 /* the 1st face in the set using the 1st node is used to define the siding-plane for all nodes in the set */
853 if( compare(spcType, "cyc", 1) == 1)
854 {
855 /* check if at least one face is in the set */
856 if(set[setNr].anz_f<1)
857 {
858 printf(" ERROR: set:%s does not contain a face which defines the sliding plane.\n", setname);
859 return;
860 }
861 i=set[setNr].face[0];
862 anz_n=n=0;
863 if (face[i].type==7) anz_n=3;
864 if (face[i].type==8) anz_n=6;
865 if (face[i].type==9) anz_n=4;
866 if (face[i].type==10) anz_n=8;
867
868 if(anz_n)
869 {
870 n0=face[i].nod[0];
871 n1=face[i].nod[1];
872 n2=face[i].nod[2];
873 if(printFlag) printf("n0:%d n1:%d n2:%d\n", n0, n1, n2);
874 p0[0]=node[n0].nx*scale->w+scale->x;
875 p0[1]=node[n0].ny*scale->w+scale->y;
876 p0[2]=node[n0].nz*scale->w+scale->z;
877 p1[0]=node[n1].nx*scale->w+scale->x;
878 p1[1]=node[n1].ny*scale->w+scale->y;
879 p1[2]=node[n1].nz*scale->w+scale->z;
880 p2[0]=node[n2].nx*scale->w+scale->x;
881 p2[1]=node[n2].ny*scale->w+scale->y;
882 p2[2]=node[n2].nz*scale->w+scale->z;
883 v_result( p0, p1, p0p1 );
884 v_result( p0, p2, p0p2 );
885
886 if (compare( format, "abq", 3)== 3)
887 {
888 sprintf(prognam, "%s.mpc", setname);
889 handle = fopen (prognam, "w");
890 if ( handle== NULL )
891 {
892 printf ("\nThe input file %s could not be opened.\n\n", prognam);
893 return;
894 }
895 strcpy(parameter[0], prognam);
896 write2stack(1, parameter);
897
898 fprintf(handle, "** Sliders based on %s\n", setname );
899
900 /* copy nodes */
901 fprintf (handle, "*NODE, NSET=N%s_COPY\n", setname );
902 for (n=0; n<set[setNr].anz_n; n++)
903 {
904 i=set[setNr].node[n];
905 fprintf( handle, "%8d,%.12e,%.12e,%.12e\n", anz->nmax+n+1, node[i].nx*scale->w+scale->x, node[i].ny*scale->w+scale->y, node[i].nz*scale->w+scale->z );
906 }
907
908 /* write name-set for the tramsformation into the sliding plane */
909 fprintf (handle, "*NSET, NSET=N%s\n", setname );
910 for (n=0; n<set[setNr].anz_n; n++)
911 {
912 i=set[setNr].node[n];
913 fprintf( handle, "%8d,\n%8d,\n", i, anz->nmax+n+1 );
914 }
915
916 /* coordinate system for the sliding plane */
917 fprintf(handle, "*TRANSFORM,NSET=N%s\n",set[setNr].name );
918 fprintf(handle, "%lf, %lf, %lf, %lf, %lf, %lf\n", p0p1[0],p0p1[1],p0p1[2], p0p2[0],p0p2[1],p0p2[2] );
919
920 /* write equations normal to the sliding plane */
921 for (n=0; n<set[setNr].anz_n; n++)
922 {
923 i=set[setNr].node[n];
924 fprintf(handle, "*EQUATION\n");
925 fprintf(handle, "%d\n", 2);
926 fprintf(handle, "%d,%d,%.12lf, %d,%d,%.12lf \n", i, 3, 1., anz->nmax+n+1, 3, -1. );
927 }
928
929 fclose(handle);
930 }
931 return;
932 }
933 else
934 {
935 printf(" ERROR: face-type:%d unknown, no siding plane could be defined.\n", face[i].type);
936 return;
937 }
938 }
939
940 /* ---- sliders ----- */
941 if(!set[setNr].anz_f)
942 {
943 printf(" WARNING: Found no faces in set:%s\n",set[setNr].name);
944 return;
945 }
946
947 if ( (sum_n = (int *)realloc( (int *)sum_n, (anz->nmax+1) * sizeof(int))) == NULL )
948 {
949 printf("WARNING: realloc failed in sendSet\n");
950 return;
951 }
952 for (i=0; i<anz->nmax; i++) sum_n[i]=0;
953 if( compare(spcType, "s", 1) == 1)
954 {
955 /* nodes slide on the element surfaces */
956
957 /* calculate the average normal on every node */
958 getNodeNormalen(&buf_n, &norm, setNr, anz, face);
959 // compare buf_n with the given nodes
960 for (i=0; i<set[setNr].anz_n; i++) sum_n[set[setNr].node[i]]=buf_n[set[setNr].node[i]];
961 free(buf_n);
962 }
963 else if( compare(spcType, "rx", 2) == 2)
964 {
965 /* calculate the average normal on every node */
966 p2[0]=1.;
967 p2[1]=0.;
968 p2[2]=0.;
969 for (i=0; i<set[setNr].anz_n; i++)
970 {
971 n= set[setNr].node[i];
972 sum_n[n]=1;
973 p1[0]=node[n].nx* scale->w+scale->x;
974 p1[1]=node[n].ny* scale->w+scale->y;
975 p1[2]=node[n].nz* scale->w+scale->z;
976 v_prod( p1, p2, p3);
977 v_norm( p3, N );
978 norm[n].nx=N[0];
979 norm[n].ny=N[1];
980 norm[n].nz=N[2];
981 }
982 }
983 else if( compare(spcType, "ry", 2) == 2)
984 {
985 /* calculate the average normal on every node */
986 p2[0]=0.;
987 p2[1]=1.;
988 p2[2]=0.;
989 for (i=0; i<set[setNr].anz_n; i++)
990 {
991 n= set[setNr].node[i];
992 sum_n[n]=1;
993 p1[0]=node[n].nx* scale->w+scale->x;
994 p1[1]=node[n].ny* scale->w+scale->y;
995 p1[2]=node[n].nz* scale->w+scale->z;
996 v_prod( p1, p2, p3);
997 v_norm( p3, N );
998 norm[n].nx=N[0];
999 norm[n].ny=N[1];
1000 norm[n].nz=N[2];
1001 }
1002 }
1003 else if( compare(spcType, "rz", 2) == 2)
1004 {
1005 /* calculate the average normal on every node */
1006 p2[0]=0.;
1007 p2[1]=0.;
1008 p2[2]=1.;
1009 for (i=0; i<set[setNr].anz_n; i++)
1010 {
1011 n= set[setNr].node[i];
1012 sum_n[n]=1;
1013 p1[0]=node[n].nx* scale->w+scale->x;
1014 p1[1]=node[n].ny* scale->w+scale->y;
1015 p1[2]=node[n].nz* scale->w+scale->z;
1016 v_prod( p1, p2, p3);
1017 v_norm( p3, N );
1018 norm[n].nx=N[0];
1019 norm[n].ny=N[1];
1020 norm[n].nz=N[2];
1021 }
1022 }
1023 else if( compare(spcType, "tx", 2) == 2)
1024 {
1025 /* calculate the average normal on every node */
1026 for (i=0; i<set[setNr].anz_n; i++)
1027 {
1028 n= set[setNr].node[i];
1029 sum_n[n]=1;
1030 norm[n].nx=0.;
1031 norm[n].ny=node[n].ny* scale->w+scale->y;
1032 norm[n].nz=node[n].nz* scale->w+scale->z;
1033 }
1034 }
1035 else if( compare(spcType, "ty", 2) == 2)
1036 {
1037 /* calculate the average normal on every node */
1038 for (i=0; i<set[setNr].anz_n; i++)
1039 {
1040 n= set[setNr].node[i];
1041 sum_n[n]=1;
1042 norm[n].nx=node[n].nx* scale->w+scale->x;
1043 norm[n].ny=0.;
1044 norm[n].nz=node[n].nz* scale->w+scale->z;
1045 }
1046 }
1047 else if( compare(spcType, "tz", 2) == 2)
1048 {
1049 /* calculate the average normal on every node */
1050 for (i=0; i<set[setNr].anz_n; i++)
1051 {
1052 n= set[setNr].node[i];
1053 sum_n[n]=1;
1054 norm[n].nx=node[n].nx* scale->w+scale->x;
1055 norm[n].ny=node[n].ny* scale->w+scale->y;
1056 norm[n].nz=0.;
1057 }
1058 }
1059 else
1060 {
1061 errMsg ("\nERROR: format:%s not known\n", spcType);
1062 return;
1063 }
1064
1065 strcpy ( prognam, setname);
1066 length= strlen ( setname );
1067 strcpy (&prognam[length], ".equ");
1068
1069 strcpy(parameter[0], prognam);
1070 write2stack(1, parameter);
1071
1072 /* write the sliders in nastran-format */
1073 /* write the sliders in abaqus-format */
1074 if (compare( format, "abq", 3)== 3)
1075 {
1076 handle = fopen (prognam, "w");
1077 if ( handle== NULL )
1078 {
1079 printf ("\nThe input file %s could not be opened.\n\n", prognam);
1080 return;
1081 }
1082 fprintf(handle, "** Sliders based on %s\n", setname);
1083 for (i=0; i<anz->n; i++ )
1084 {
1085 if( sum_n[node[i].nr] >0 )
1086 {
1087 printf("node %d Norm:%lf %lf %lf Koord:%lf %lf %lf\n"
1088 , node[i].nr
1089 , norm[node[i].nr].nx, norm[node[i].nr].ny, norm[node[i].nr].nz
1090 ,node[node[i].nr].nx,node[node[i].nr].ny,node[node[i].nr].nz );
1091
1092 xx=norm[node[i].nr].nx*norm[node[i].nr].nx;
1093 yy=norm[node[i].nr].ny*norm[node[i].nr].ny;
1094 zz=norm[node[i].nr].nz*norm[node[i].nr].nz;
1095 if((xx>MIN_VECTOR)&&(yy>MIN_VECTOR)
1096 &&(zz>MIN_VECTOR))
1097 {
1098 fprintf(handle, "*EQUATION\n");
1099 fprintf(handle, "%d\n", 3);
1100 fprintf(handle, "%d,%d,%lf, %d,%d,%lf, %d,%d,%lf \n"
1101 , node[i].nr, DOFX, norm[node[i].nr].nx
1102 , node[i].nr, DOFY, norm[node[i].nr].ny
1103 , node[i].nr, DOFZ, norm[node[i].nr].nz );
1104 }
1105 else if((xx<=MIN_VECTOR)
1106 &&(yy>MIN_VECTOR)&&(zz>MIN_VECTOR))
1107 {
1108 fprintf(handle, "*EQUATION\n");
1109 fprintf(handle, "%d\n", 2);
1110 fprintf(handle, "%d,%d,%lf, %d,%d,%lf \n"
1111 , node[i].nr, DOFY, norm[node[i].nr].ny
1112 , node[i].nr, DOFZ, norm[node[i].nr].nz );
1113 }
1114 else if((yy<=MIN_VECTOR)
1115 &&(xx>MIN_VECTOR)&&(zz>MIN_VECTOR))
1116 {
1117 fprintf(handle, "*EQUATION\n");
1118 fprintf(handle, "%d\n", 2);
1119 fprintf(handle, "%d,%d,%lf, %d,%d,%lf \n"
1120 , node[i].nr, DOFX, norm[node[i].nr].nx
1121 , node[i].nr, DOFZ, norm[node[i].nr].nz );
1122 }
1123 else if((zz<=MIN_VECTOR)
1124 &&(xx>MIN_VECTOR)&&(yy>MIN_VECTOR))
1125 {
1126 fprintf(handle, "*EQUATION\n");
1127 fprintf(handle, "%d\n", 2);
1128 fprintf(handle, "%d,%d,%lf, %d,%d,%lf \n"
1129 , node[i].nr, DOFX, norm[node[i].nr].nx
1130 , node[i].nr, DOFY, norm[node[i].nr].ny );
1131 }
1132 else if((xx>MIN_VECTOR)
1133 &&(yy<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
1134 {
1135 fprintf(handle, "*BOUNDARY\n");
1136 fprintf(handle, "%d,%d \n"
1137 , node[i].nr, DOFX );
1138 }
1139 else if((yy>MIN_VECTOR)
1140 &&(xx<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
1141 {
1142 fprintf(handle, "*BOUNDARY\n");
1143 fprintf(handle, "%d,%d \n"
1144 , node[i].nr, DOFY );
1145 }
1146 else if((zz>MIN_VECTOR)
1147 &&(xx<=MIN_VECTOR)&&(yy<=MIN_VECTOR))
1148 {
1149 fprintf(handle, "*BOUNDARY\n");
1150 fprintf(handle, "%d,%d \n"
1151 , node[i].nr, DOFZ );
1152 }
1153 else printf("ERROR; no slider created for node:%d\n", node[i].nr);
1154 }
1155 }
1156 fclose(handle);
1157 }
1158 /* write the sliders in ansys-format */
1159 else if (compare( format, "ans", 3)== 3)
1160 {
1161 handle = fopen (prognam, "w");
1162 if ( handle== NULL )
1163 {
1164 printf ("\nThe input file %s could not be opened.\n\n", prognam);
1165 return;
1166 }
1167 fprintf(handle, "! Sliders based on %s\n", setname);
1168 for (i=0; i<anz->n; i++ )
1169 {
1170 if( sum_n[node[i].nr] >0 )
1171 {
1172 printf("node %d Norm:%lf %lf %lf Koord:%lf %lf %lf\n"
1173 , node[i].nr
1174 , norm[node[i].nr].nx, norm[node[i].nr].ny, norm[node[i].nr].nz
1175 ,node[node[i].nr].nx,node[node[i].nr].ny,node[node[i].nr].nz );
1176
1177 xx=norm[node[i].nr].nx*norm[node[i].nr].nx;
1178 yy=norm[node[i].nr].ny*norm[node[i].nr].ny;
1179 zz=norm[node[i].nr].nz*norm[node[i].nr].nz;
1180 if((xx>MIN_VECTOR)&&(yy>MIN_VECTOR)
1181 &&(zz>MIN_VECTOR))
1182 {
1183 neqn++;
1184 fprintf(handle, "CE,%d,0,%d,%s,%lf, %d,%s,%lf, %d,%s,%lf\n", neqn
1185 , node[i].nr, "UX", norm[node[i].nr].nx
1186 , node[i].nr, "UY", norm[node[i].nr].ny
1187 , node[i].nr, "UZ", norm[node[i].nr].nz );
1188 }
1189 else if((xx<=MIN_VECTOR)
1190 &&(yy>MIN_VECTOR)&&(zz>MIN_VECTOR))
1191 {
1192 neqn++;
1193 fprintf(handle, "CE,%d,0,%d,%s,%lf, %d,%s,%lf, %d,%s,%lf\n", neqn
1194 , -node[i].nr, "UX", norm[node[i].nr].nx
1195 , node[i].nr, "UY", norm[node[i].nr].ny
1196 , node[i].nr, "UZ", norm[node[i].nr].nz );
1197 }
1198 else if((yy<=MIN_VECTOR)
1199 &&(xx>MIN_VECTOR)&&(zz>MIN_VECTOR))
1200 {
1201 neqn++;
1202 fprintf(handle, "CE,%d,0,%d,%s,%lf, %d,%s,%lf, %d,%s,%lf\n", neqn
1203 , node[i].nr, "UX", norm[node[i].nr].nx
1204 , -node[i].nr, "UY", norm[node[i].nr].ny
1205 , node[i].nr, "UZ", norm[node[i].nr].nz );
1206 }
1207 else if((zz<=MIN_VECTOR)
1208 &&(xx>MIN_VECTOR)&&(yy>MIN_VECTOR))
1209 {
1210 neqn++;
1211 fprintf(handle, "CE,%d,0,%d,%s,%lf, %d,%s,%lf, %d,%s,%lf\n", neqn
1212 , node[i].nr, "UX", norm[node[i].nr].nx
1213 , node[i].nr, "UY", norm[node[i].nr].ny
1214 , -node[i].nr, "UZ", norm[node[i].nr].nz );
1215 }
1216 else if((xx>MIN_VECTOR)
1217 &&(yy<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
1218 {
1219 fprintf(handle, "D, %d, UX, 0. \n"
1220 , node[i].nr );
1221 }
1222 else if((yy>MIN_VECTOR)
1223 &&(xx<=MIN_VECTOR)&&(zz<=MIN_VECTOR))
1224 {
1225 fprintf(handle, "D, %d, UY, 0. \n"
1226 , node[i].nr );
1227 }
1228 else if((zz>MIN_VECTOR)
1229 &&(xx<=MIN_VECTOR)&&(yy<=MIN_VECTOR))
1230 {
1231 fprintf(handle, "D, %d, UZ, 0. \n"
1232 , node[i].nr );
1233 }
1234 else printf("ERROR; no slider created for node:%d\n", node[i].nr);
1235 }
1236 }
1237 fclose(handle);
1238 }
1239 else
1240 {
1241 errMsg(" ERROR: format %s not yet supported\n", format );
1242 }
1243
1244 free(norm);
1245 free(sum_n);
1246
1247 printf (" ready\n");
1248 }
1249
1250
sendQuadLin(char * setname,char * format,Summen * anz,Nodes * nod,Elements * e_enqire)1251 void sendQuadLin( char *setname, char *format, Summen *anz, Nodes *nod, Elements *e_enqire )
1252 {
1253 int setNr, anz_n=0;
1254 int i,j,e=0,k,n,ipuf=0;
1255 char prognam[MAX_LINE_LENGTH];
1256 FILE *handle=NULL;
1257 int anz_nmax, enr=1;
1258
1259 Nodes *node=NULL;
1260
1261 /* 8*4 */
1262 int tet10tet[]={4,1,5,8, 5,2,6,9, 6,0,4,7, 7,8,9,3, 4,5,6,7, 4,5,7,8, 6,7,5,9, 8,9,5,7 };
1263 /* 8*6 incl midside nodes */
1264 int pe15pe[]= {0,6,8,9,15,17, 9,15,17,3,12,14, 8,7,2,17,16,11, 17,16,11,14,13,5, 6,7,8,15,16,17, 15,16,17,12,13,14, 1,7,6,10,16,15, 10,16,15,4,13,12 };
1265 /* 8*8 incl midside and midvolume nodes */
1266 int hex20hex[]={0,8,24,11, 12,20,26,23, 11,24,10,3, 23,26,22,15, 8,1,9,24, 20,13,21,26, 24,9,2,10, 26,21,14,22,
1267 12,20,26,23, 4,16,25,19, 23,26,22,15, 19,25,18,7, 20,13,21,26, 16,5,17,25, 26,21,14,22, 25,17,6,18 };
1268
1269 static Rsort *rsort=NULL;
1270
1271 static double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
1272 static int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL, near_node[10];
1273 double dr, dx, dy, dz,tol;
1274
1275 double pcoords[3]={0.5,0.5,0.5}, weights[20];
1276
1277 setNr=getSetNr(setname);
1278 if (setNr<0)
1279 {
1280 printf (" ERROR: set:%s does not exist\n", setname);
1281 return;
1282 }
1283
1284 tol=0.00001;
1285 tol*=tol;
1286
1287 enr=set[setNr].elem[0];
1288
1289 sprintf(prognam,"%s_lin.msh",setname);
1290 printf (" write file: %s\n", prognam );
1291 strcpy(parameter[0], prognam);
1292 write2stack(1, parameter);
1293
1294 /* copy all nodes */
1295
1296 if ( (node = (Nodes *)realloc( (Nodes *)node, (anz->nmax+1) * sizeof(Nodes))) == NULL )
1297 printf("WARNING: realloc error\n");
1298
1299 for (i=0; i<anz->n; i++)
1300 {
1301 node[i].nr=nod[i].nr;
1302 j=node[i].nr;
1303 node[j].indx=-1;
1304 node[j].pflag=0;
1305 node[j].nx=nod[j].nx;
1306 node[j].ny=nod[j].ny;
1307 node[j].nz=nod[j].nz;
1308 }
1309 descalNodes ( anz->n, node, scale);
1310 anz_nmax=anz->nmax;
1311
1312 /* merge nodes */
1313 /* search the closest node */
1314 if ( (rsort = (Rsort *)malloc( (anz->n+1) * sizeof(Rsort))) == NULL )
1315 printf("ERROR: realloc failed: Rsort\n\n" );
1316 if ( (orig_x = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1317 printf("ERROR: realloc failed in areampc\n\n" );
1318 if ( (orig_y = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1319 printf("ERROR: realloc failed in areampc\n\n" );
1320 if ( (orig_z = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1321 printf("ERROR: realloc failed in areampc\n\n" );
1322 if ( (sort_x = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1323 printf("ERROR: realloc failed in areampc\n\n" );
1324 if ( (sort_y = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1325 printf("ERROR: realloc failed in areampc\n\n" );
1326 if ( (sort_z = (double *)malloc( (anz->n+1) * sizeof(double))) == NULL )
1327 printf("ERROR: realloc failed in areampc\n\n" );
1328 if ( (sort_nx = (int *)malloc( (anz->n+1) * sizeof(int))) == NULL )
1329 printf("ERROR: realloc failed in areampc\n\n" );
1330 if ( (sort_ny = (int *)malloc( (anz->n+1) * sizeof(int))) == NULL )
1331 printf("ERROR: realloc failed in areampc\n\n" );
1332 if ( (sort_nz = (int *)malloc( (anz->n+1) * sizeof(int))) == NULL )
1333 printf("ERROR: realloc failed in areampc\n\n" );
1334 for(i=0; i<anz->n; i++)
1335 {
1336 rsort[i].r=orig_x[i]=node[node[i].nr].nx;
1337 rsort[i].i=i;
1338 }
1339 qsort( rsort, anz->n, sizeof(Rsort), (void *)compareRsort );
1340 for(i=0; i<anz->n; i++)
1341 {
1342 sort_x[i]=rsort[i].r;
1343 sort_nx[i]=rsort[i].i;
1344 }
1345 for(i=0; i<anz->n; i++)
1346 {
1347 rsort[i].r=orig_y[i]=node[node[i].nr].ny;
1348 rsort[i].i=i;
1349 }
1350 qsort( rsort, anz->n, sizeof(Rsort), (void *)compareRsort );
1351 for(i=0; i<anz->n; i++)
1352 {
1353 sort_y[i]=rsort[i].r;
1354 sort_ny[i]=rsort[i].i;
1355 }
1356 for(i=0; i<anz->n; i++)
1357 {
1358 rsort[i].r=orig_z[i]=node[node[i].nr].nz;
1359 rsort[i].i=i;
1360 }
1361 qsort( rsort, anz->n, sizeof(Rsort), (void *)compareRsort );
1362 for(i=0; i<anz->n; i++)
1363 {
1364 sort_z[i]=rsort[i].r;
1365 sort_nz[i]=rsort[i].i;
1366 }
1367
1368 /* aktivate nodes and generate midvolume nodes for hex20 */
1369 anz_n=anz->n;
1370 for (i=0; i<set[setNr].anz_e; i++ )
1371 {
1372 e=set[setNr].elem[i];
1373 switch(e_enqire[e].type)
1374 {
1375 case 1:
1376 ipuf = 8;
1377 break;
1378 case 2:
1379 ipuf = 6;
1380 break;
1381 case 3:
1382 ipuf = 4;
1383 break;
1384 case 4:
1385 ipuf = 27;
1386
1387 /* generate mid-volume node */
1388 anz_nmax++;
1389 if ( (node = (Nodes *)realloc( (Nodes *)node, (anz_nmax+1) * sizeof(Nodes))) == NULL )
1390 printf("\n\n ERROR: realloc failed node\n\n") ;
1391
1392 shapeHe20(pcoords[0],pcoords[1],pcoords[2], (double (*)[3])NULL, NULL, weights, 1);
1393 node[anz_nmax].nx =node[anz_nmax].ny =node[anz_nmax].nz = 0.;
1394 for(j=0; j<20; j++)
1395 {
1396 node[anz_nmax].nx+=node[e_enqire[e].nod[j]].nx * weights[j];
1397 node[anz_nmax].ny+=node[e_enqire[e].nod[j]].ny * weights[j];
1398 node[anz_nmax].nz+=node[e_enqire[e].nod[j]].nz * weights[j];
1399 }
1400 node[anz_n].nr=anz_nmax;
1401 anz_n++;
1402 node[anz_nmax].indx=-1;
1403 node[anz_nmax].pflag=1;
1404 e_enqire[ e ].nod[26]=anz_nmax;
1405
1406 /* use common nodes on the mid-face positions (merge) */
1407 /* first, search for a close node */
1408 for(j=20; j<26; j++)
1409 {
1410 n=e_enqire[ e ].nod[j];
1411 near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, node[n].nx,node[n].ny,
1412 node[n].nz, anz->n, &near_node[0], 2);
1413 for(k=0;k<2; k++)
1414 {
1415 if(node[near_node[k]].nr!=n)
1416 {
1417 // printf("node:%d near node:%d \n",n, node[near_node[k]].nr);
1418 dx= node[node[near_node[k]].nr].nx - node[n].nx;
1419 dy= node[node[near_node[k]].nr].ny - node[n].ny;
1420 dz= node[node[near_node[k]].nr].nz - node[n].nz;
1421 dr=dx*dx + dy*dy + dz*dz;
1422 if(dr<tol )
1423 {
1424 if(printFlag) printf("node:%d, found equal node:%d with dr:%lf\n", n, node[near_node[k]].nr, sqrt(dr));
1425 if(node[n].indx==-1)
1426 { node[n].pflag=0; node[n].indx=node[near_node[k]].nr; node[node[near_node[k]].nr].indx=node[n].indx; }
1427 }
1428 break;
1429 }
1430 }
1431 }
1432 break;
1433 case 5:
1434 ipuf = 18;
1435
1436 /* use common nodes on the mid-face positions (merge) */
1437 /* first, search for a close node */
1438 for(j=15; j<18; j++)
1439 {
1440 n=e_enqire[ e ].nod[j];
1441 near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, node[n].nx,node[n].ny,
1442 node[n].nz, anz->n, &near_node[0], 2);
1443 for(k=0;k<2; k++)
1444 {
1445 if(node[near_node[k]].nr!=n)
1446 {
1447 // printf("node:%d near node:%d \n",n, node[near_node[k]].nr);
1448 dx= node[node[near_node[k]].nr].nx - node[n].nx;
1449 dy= node[node[near_node[k]].nr].ny - node[n].ny;
1450 dz= node[node[near_node[k]].nr].nz - node[n].nz;
1451 dr=dx*dx + dy*dy + dz*dz;
1452 if(dr<tol )
1453 {
1454 if(printFlag) printf("node:%d, found equal node:%d with dr:%lf\n", n, node[near_node[k]].nr, sqrt(dr));
1455 if(node[n].indx==-1)
1456 { node[n].pflag=0; node[n].indx=node[near_node[k]].nr; node[node[near_node[k]].nr].indx=node[n].indx; }
1457 }
1458 break;
1459 }
1460 }
1461 }
1462 break;
1463 case 6:
1464 ipuf = 10;
1465 break;
1466 case 7:
1467 ipuf = 3;
1468 break;
1469 case 8:
1470 ipuf = 6;
1471 break;
1472 case 9:
1473 ipuf = 4;
1474 break;
1475 case 10:
1476 ipuf = 8;
1477 break;
1478 case 11:
1479 ipuf = 2;
1480 break;
1481 case 12:
1482 ipuf = 3;
1483 break;
1484 }
1485 for (n=0; n<ipuf; n++)
1486 {
1487 node[e_enqire[e].nod[n]].pflag=1;
1488 }
1489 }
1490 for (n=0; n<anz_n; n++) if(node[node[n].nr].indx==-1) node[node[n].nr].indx=node[n].nr;
1491
1492 /* write abaqus-format */
1493 if (compare( format, "abq", 3)== 3)
1494 {
1495 handle = fopen (prognam, "w");
1496 if ( handle== NULL )
1497 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
1498 fprintf(handle, "** Linear elements based on %s\n", setname);
1499
1500 fprintf(handle,"*NODE, NSET=Nall\n");
1501 for (i=0; i<anz_n; i++ )
1502 {
1503 j=node[i].nr;
1504 if(node[j].pflag==1) fprintf(handle," %d,%f,%f,%f\n", j,node[j].nx,node[j].ny,node[j].nz );
1505 }
1506 for (i=0; i<set[setNr].anz_e; i++ )
1507 {
1508 e=set[setNr].elem[i];
1509 switch(e_enqire[e].type)
1510 {
1511 case 1:
1512 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D8\n", e);
1513 fprintf(handle,"%d", enr++);
1514 for (k=0; k<8; k++)
1515 {
1516 fprintf(handle,",%d", e_enqire[e].nod[k]);
1517 }
1518 fprintf(handle,"\n");
1519 break;
1520 case 2:
1521 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D6\n", e);
1522 fprintf(handle,"%d", enr++);
1523 for (k=0; k<6; k++)
1524 {
1525 fprintf(handle,",%d", e_enqire[e].nod[k]);
1526 }
1527 fprintf(handle,"\n");
1528 break;
1529 case 3:
1530 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D4\n", e);
1531 fprintf(handle,"%d", enr++);
1532 for (k=0; k<4; k++)
1533 {
1534 fprintf(handle,",%d", e_enqire[e].nod[k]);
1535 }
1536 fprintf(handle,"\n");
1537 break;
1538 case 4:
1539 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D8\n", e);
1540 for (j=0; j<8; j++)
1541 {
1542 fprintf(handle,"%d", enr++);
1543 for (k=0; k<8; k++)
1544 {
1545 fprintf(handle,",%d", node[ e_enqire[e].nod[hex20hex[8*j+k]] ].indx);
1546 }
1547 fprintf(handle,"\n");
1548 }
1549 break;
1550 case 5:
1551 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D6\n", e);
1552 for (j=0; j<8; j++)
1553 {
1554 fprintf(handle,"%d", enr++);
1555 for (k=0; k<6; k++)
1556 {
1557 fprintf(handle,",%d", node[ e_enqire[e].nod[pe15pe[6*j+k]] ].indx);
1558 }
1559 fprintf(handle,"\n");
1560 }
1561 break;
1562 case 6:
1563 fprintf(handle,"** elem:%d\n*ELEMENTS, TYPE=C3D4\n", e);
1564 for (j=0; j<8; j++)
1565 {
1566 fprintf(handle,"%d", enr++);
1567 for (k=0; k<4; k++)
1568 {
1569 fprintf(handle,",%d", e_enqire[e].nod[tet10tet[4*j+k]]);
1570 }
1571 fprintf(handle,"\n");
1572 }
1573 break;
1574 default:
1575 printf(" ERROR: Elem:%d type:%d not supported\n",e, e_enqire[e].type);
1576 break;
1577 }
1578 }
1579 }
1580 else
1581 {
1582 errMsg(" ERROR: format %s not yet supported\n", format );
1583 }
1584
1585 fclose(handle);
1586 scalNodes ( anz->n, node, scale); // necessary to reset the scale flag in scalNodes
1587 free(node);
1588 printf (" ready\n");
1589 }
1590
1591
1592
1593 /* val4 holds the dofs when this function is used for *writing BOUNDARYF commands */
sendPressure(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * val1,char * val2,char * val3,char * val4)1594 void sendPressure( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *val1, char *val2, char *val3, char *val4 )
1595 {
1596 int setNr;
1597 int i,j;
1598 char prognam[MAX_LINE_LENGTH];
1599 double *pressure;
1600 FILE *handle;
1601 int n, lc, entity;
1602
1603 setNr=getSetNr(setname);
1604 if (setNr<0)
1605 {
1606 printf (" ERROR: set:%s does not exist\n", setname);
1607 return;
1608 }
1609 /* do not use this code, otherwhise constant values can not be used
1610 if (atoi(&val2[1])<1)
1611 {
1612 printf (" ERROR: entity:%s does not exist\n", val2 );
1613 return;
1614 }
1615 */
1616
1617 if(compare(val1, "ds", 2)==2) sprintf(prognam,"%s_%s%s",setname,val1,val2);
1618 else
1619 sprintf(prognam,"%s",setname);
1620 if(val4) sprintf(&prognam[strlen(prognam)],"_%s.bouf",val4);
1621 //if(val4) sprintf(&prognam[strlen(prognam)],".bouf");
1622 else sprintf(&prognam[strlen(prognam)],".dlo");
1623 printf (" write file: %s\n", prognam );
1624
1625 strcpy(parameter[0], prognam);
1626 write2stack(1, parameter);
1627
1628 if((pressure = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
1629 printf("\n\n ERROR: malloc failure\n\n" );
1630
1631 /* check if a constant value or a dataset has to be used */
1632 if(compare(val1, "ds", 2)==2)
1633 {
1634 lc=atoi(&val1[2])-1;
1635 entity=atoi(&val2[1])-1;
1636
1637 /* check if this lc and entity are valid */
1638 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
1639 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
1640
1641 /* check if the data of the specified lcase (Dataset) are already available */
1642 if (!lcase[lc].loaded)
1643 {
1644 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
1645 {
1646 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
1647 return;
1648 }
1649 calcDatasets( lc, anz, node, lcase );
1650 recompileEntitiesInMenu(lc);
1651 }
1652
1653 /* calculate the average load on that face */
1654 for (j=0; j<set[setNr].anz_f; j++ )
1655 {
1656 i=set[setNr].face[j];
1657 pressure[j]=0.;
1658 if(face[i].type==7)
1659 {
1660 for(n=0; n<3; n++) pressure[j]+=lcase[lc].dat[entity][face[i].nod[n]];
1661 pressure[j]/=3.;
1662 }
1663 else if(face[i].type==8)
1664 {
1665 for(n=0; n<6; n++) pressure[j]+=lcase[lc].dat[entity][face[i].nod[n]];
1666 pressure[j]/=6.;
1667 }
1668 else if(face[i].type==9)
1669 {
1670 for(n=0; n<4; n++) pressure[j]+=lcase[lc].dat[entity][face[i].nod[n]];
1671 pressure[j]/=4.;
1672 }
1673 else if(face[i].type==10)
1674 {
1675 for(n=0; n<8; n++) pressure[j]+=lcase[lc].dat[entity][face[i].nod[n]];
1676 pressure[j]/=8.;
1677 }
1678 else
1679 {
1680 printf(" Not supported for this element type, load set to 0.\n");
1681 pressure[i]=0.;
1682 }
1683 }
1684 }
1685 else
1686 {
1687 for (j=0; j<set[setNr].anz_f; j++ ) pressure[j]=atof(val1);
1688 }
1689
1690 /* write the pressure in nastran-format */
1691 if (compare( format, "nas", 3)== 3)
1692 {
1693 handle = fopen (prognam, "w");
1694 if ( handle== NULL )
1695 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
1696 fprintf(handle, "$ Pressure based on %s\n", setname);
1697 for (j=0; j<set[setNr].anz_f; j++ )
1698 {
1699 i=set[setNr].face[j];
1700 if (face[i].type==9)
1701 {
1702 fprintf(handle, "PLOAD4,%8d,%8d,%12.5e, , , ,%8d,%8d\n",
1703 1, face[i].elem_nr, pressure[j], face[i].nod[0], face[i].nod[2] );
1704 }
1705 else
1706 printf(" Pressure not supported for this element type:%d\n", face[i].type);
1707 }
1708 fclose(handle);
1709 }
1710 /* write the pressure in abaqus-format */
1711 else if (compare( format, "abq", 3)== 3)
1712 {
1713 handle = fopen (prognam, "w");
1714 if ( handle== NULL )
1715 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
1716 if(val4) fprintf(handle, "** BOUNDARYF based on %s\n", setname);
1717 else fprintf(handle, "** Pressure based on %s\n", setname);
1718 for (j=0; j<set[setNr].anz_f; j++ )
1719 {
1720 i=set[setNr].face[j];
1721 if(e_enqire[face[i].elem_nr].type>6) // shell
1722 {
1723 if(e_enqire[face[i].elem_nr].type>10) // beam
1724 {
1725 if(val4) fprintf( handle, "%d, S?, %s,, %e \n", face[i].elem_nr, val4, pressure[j]);
1726 else fprintf( handle, "%d, P?, %e \n", face[i].elem_nr, pressure[j]);
1727 }
1728 else if(e_enqire[face[i].elem_nr].attr>3) // plain strain,stress or axissym
1729 {
1730 /* only the surrounding faces are applicable */
1731 if(val4) fprintf( handle, "%d, S%d, %s,, %e\n", face[i].elem_nr, face[i].nr-1, val4, pressure[j]);
1732 else fprintf( handle, "%d, P%d, %e\n", face[i].elem_nr, face[i].nr-1, pressure[j]);
1733 }
1734 else
1735 {
1736 if(face[i].nr==1)
1737 {
1738 if(val4) fprintf( handle, "%d, S, %s,, %e\n", face[i].elem_nr, val4, pressure[j]);
1739 else fprintf( handle, "%d, P, %e\n", face[i].elem_nr, pressure[j]);
1740 }
1741 else
1742 {
1743 if(val4) fprintf( handle, "%d, EDNOR%d, %s,,%e\n", face[i].elem_nr, face[i].nr-1, val4, pressure[j]);
1744 else fprintf( handle, "%d, EDNOR%d, %e\n", face[i].elem_nr, face[i].nr-1, pressure[j]);
1745 }
1746 }
1747 }
1748 else
1749 {
1750 if(val4) fprintf( handle, "%d, S%d, %s,, %e\n", face[i].elem_nr, face[i].nr+1, val4, pressure[j]);
1751 else fprintf( handle, "%d, P%d, %e\n", face[i].elem_nr, face[i].nr+1, pressure[j]);
1752 }
1753 }
1754 fclose(handle);
1755 }
1756 /* write the pressure in ansys-format */
1757 else if (compare( format, "ans", 3)== 3)
1758 {
1759 handle = fopen (prognam, "w");
1760 if ( handle== NULL )
1761 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
1762 fprintf(handle, "! Pressure based on %s\n", setname);
1763 fprintf(handle, "! Consider to use the /INPUT command in the main file for reference\n");
1764 fprintf(handle, "! /INPUT, Fname, Ext, Dir, LINE, LOG\n");
1765 fprintf(handle, "! /INPUT, %s,,,,\n", prognam);
1766 for (j=0; j<set[setNr].anz_f; j++ )
1767 {
1768 i=set[setNr].face[j];
1769 if((e_enqire[face[i].elem_nr].type==1)||(e_enqire[face[i].elem_nr].type==4)) // he8,he20
1770 {
1771 if (face[i].nr==0)
1772 fprintf(handle, "SFE, %d, 1, PRES, ,%e \n",
1773 face[i].elem_nr, pressure[j] );
1774 else if (face[i].nr==1)
1775 fprintf(handle, "SFE, %d, 6, PRES, ,%e \n",
1776 face[i].elem_nr, pressure[j] );
1777 else if (face[i].nr==2)
1778 fprintf(handle, "SFE, %d, 2, PRES, ,%e \n",
1779 face[i].elem_nr, pressure[j] );
1780 else if (face[i].nr==3)
1781 fprintf(handle, "SFE, %d, 3, PRES, ,%e \n",
1782 face[i].elem_nr, pressure[j] );
1783 else if (face[i].nr==4)
1784 fprintf(handle, "SFE, %d, 4, PRES, ,%e \n",
1785 face[i].elem_nr, pressure[j] );
1786 else if (face[i].nr==5)
1787 fprintf(handle, "SFE, %d, 5, PRES, ,%e \n",
1788 face[i].elem_nr, pressure[j] );
1789 }
1790 else if((e_enqire[face[i].elem_nr].type==2)||(e_enqire[face[i].elem_nr].type==5)) // pe6,pe15
1791 {
1792 if (face[i].nr==0)
1793 fprintf(handle, "SFE, %d, 1, PRES, ,%e \n",
1794 face[i].elem_nr, pressure[j] );
1795 else if (face[i].nr==1)
1796 fprintf(handle, "SFE, %d, 6, PRES, ,%e \n",
1797 face[i].elem_nr, pressure[j] );
1798 else if (face[i].nr==2)
1799 fprintf(handle, "SFE, %d, 2, PRES, ,%e \n",
1800 face[i].elem_nr, pressure[j] );
1801 else if (face[i].nr==3)
1802 fprintf(handle, "SFE, %d, 3, PRES, ,%e \n",
1803 face[i].elem_nr, pressure[j] );
1804 else if (face[i].nr==4)
1805 fprintf(handle, "SFE, %d, 4, PRES, ,%e \n",
1806 face[i].elem_nr, pressure[j] );
1807 }
1808 else if((e_enqire[face[i].elem_nr].type==3)||(e_enqire[face[i].elem_nr].type==6)) // te4,te10
1809 {
1810 fprintf(handle, "SFE, %d, %d, PRES, ,%e \n",
1811 face[i].elem_nr, face[i].nr+1, pressure[j] );
1812 }
1813 else
1814 {
1815 errMsg(" ERROR: elemet type %d not yet supported\n", e_enqire[face[i].elem_nr].type );
1816 }
1817 }
1818 fclose(handle);
1819 }
1820 else
1821 {
1822 errMsg(" ERROR: format %s not yet supported\n", format );
1823 }
1824 free(pressure);
1825 printf (" ready\n");
1826 }
1827
1828
sendFilm(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * val1,char * val2,char * val3,char * val4,char * val5)1829 void sendFilm( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *val1, char *val2, char *val3, char *val4, char *val5 )
1830 {
1831 int setNr;
1832 int i,j, ipuf;
1833 char prognam[MAX_LINE_LENGTH];
1834 char typelabel[MAX_LINE_LENGTH];
1835 char **amp_t=NULL, **amp_a=NULL;
1836 double *temp, *alpha, value=0;
1837 FILE *handle;
1838 int n, lc=0, entity;
1839 int lcmin=0, lcmax=0;
1840 int *dsNr=NULL, anz_lc=0;
1841 int orif=1;
1842
1843 setNr=getSetNr(setname);
1844 if (setNr<0)
1845 {
1846 printf (" ERROR: set:%s does not exist\n", setname);
1847 return;
1848 }
1849
1850 if( ((val1!=NULL)&&(val1[0]=='-'))||((val2!=NULL)&&(val2[0]=='-'))||((val3!=NULL)&&(val3[0]=='-'))||((val4!=NULL)&&(val4[0]=='-'))||((val5!=NULL)&&(val5[0]=='-')) ) orif=0;
1851
1852 if((temp = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
1853 printf("\n\n ERROR: malloc failure\n\n" );
1854 if((alpha = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
1855 printf("\n\n ERROR: malloc failure\n\n" );
1856
1857
1858 printf("film: %s %s %s %s\n",val1,val2,val3,val4);
1859
1860 /* check if a node, constant value or a dataset has to be used */
1861 typelabel[0]=0;
1862 if(compare(val1, "n", 1)==1)
1863 {
1864 strcpy(typelabel,"FC");
1865 for (j=0; j<set[setNr].anz_f; j++ ) temp[j]=(float)atoi(&val1[1]);
1866 }
1867 else if(compare(val1, "ds", 2)==2)
1868 {
1869 lc=atoi(&val1[2])-1;
1870 entity=atoi(&val2[1])-1;
1871
1872 /* check if this lc and entity are valid */
1873 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
1874 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
1875
1876 /* check if the data of the specified lcase (Dataset) are already available */
1877 if (!lcase[lc].loaded)
1878 {
1879 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
1880 {
1881 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
1882 return;
1883 }
1884 calcDatasets( lc, anz, node, lcase );
1885 recompileEntitiesInMenu(lc);
1886 }
1887
1888 /* calculate the average load on that face */
1889 for (j=0; j<set[setNr].anz_f; j++ )
1890 {
1891 i=set[setNr].face[j];
1892 temp[j]=0.;
1893 ipuf=0;
1894 if(face[i].type==7) ipuf=3;
1895 else if(face[i].type==8) ipuf=6;
1896 else if(face[i].type==9) ipuf=4;
1897 else if(face[i].type==10) ipuf=8;
1898 else printf(" Not supported for this element type:%d, alpha set to 0.\n",face[i].type);
1899 if(ipuf)
1900 {
1901 for(n=0; n<ipuf; n++) temp[j]+=lcase[lc].dat[entity][face[i].nod[n]];
1902 temp[j]/=ipuf;
1903 }
1904 }
1905 }
1906 else if(compare(val1, "sq", 2)==2)
1907 {
1908 /* get the range of datasets */
1909 sscanf(&val1[2],"%d-%d", &lcmin, &lcmax);
1910 entity=atoi(&val2[1])-1;
1911 lcmin--;
1912 lcmax--;
1913
1914 /* check if this lc and entity are valid */
1915 if((lcmin>anz->l)||(lcmax>=anz->l)||(lcmax<=lcmin)||(lcase[lc].ncomps<entity))
1916 { printf("ERROR: ds:%d, %d or entity:%d in error\n",lcmin+1, lcmax+1, entity+1); return; }
1917
1918 printf("use lc from %d to %d of type:%s and entity:%s\n", lcmin+1, lcmax+1, lcase[lcmin].name, lcase[lcmin].compName[entity]);
1919
1920 /* compile the lc-data based on a dataset-name */
1921 anz_lc=0;
1922 for(lc=lcmin; lc<=lcmax; lc++)
1923 {
1924 if( compare( lcase[lc].name, lcase[lcmin].name, strlen(lcase[lcmin].name)) == strlen(lcase[lcmin].name) )
1925 //if(compareStrings(lcase[lc].name, lcase[lcmin].name)>0)
1926 {
1927 anz_lc++;
1928 if((dsNr=(int *)realloc((int *)dsNr, (anz_lc+2) *sizeof(int)))==NULL )
1929 printf("\n\n ERROR: malloc failed \n\n") ;
1930 dsNr[anz_lc]=lc;
1931 }
1932 }
1933 if(!anz_lc)
1934 {
1935 printf(" ERROR: found no matching Dataset for string:%s\n", lcase[lcmin].name);
1936 return;
1937 }
1938 dsNr[0]=anz_lc;
1939
1940 /* check if the data of the specified lcase (Dataset) are already available */
1941 printf (" please wait, loading data\n");
1942 for(i=1; i<=dsNr[0]; i++)
1943 {
1944 lc=dsNr[i];
1945 if (!lcase[lc].loaded)
1946 {
1947 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
1948 {
1949 printf("ERROR in sendFilm: Could not read data for Dataset:%d\n", lc+1);
1950 return;
1951 }
1952 calcDatasets( lc, anz, node, lcase );
1953 recompileEntitiesInMenu(lc);
1954 }
1955 }
1956
1957
1958 /* store the amplitudes for all faces */
1959 if ( (amp_t = (char **)malloc( (set[setNr].anz_f+1) * sizeof(char *))) == NULL )
1960 printf("\n\n ERROR: malloc failed \n\n") ;
1961
1962 /* write in abaqus-format */
1963 if (compare( format, "abq", 3)== 3)
1964 {
1965 sprintf(prognam,"%s_temp.amp",setname);
1966 printf (" write file: %s\n", prognam );
1967 handle = fopen (prognam, "w");
1968 if ( handle== NULL )
1969 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
1970 fprintf(handle, "** Film based on %s\n", setname);
1971
1972 strcpy(parameter[0], prognam);
1973 write2stack(1, parameter);
1974
1975 for (j=0; j<set[setNr].anz_f; j++ )
1976 {
1977 i=set[setNr].face[j];
1978 if ( (amp_t[j] = (char *)malloc( (MAX_LINE_LENGTH) * sizeof(char))) == NULL )
1979 printf("\n\n ERROR: malloc failed \n\n") ;
1980 sprintf(amp_t[j],"ampt_%d_%d",face[i].elem_nr, face[i].nr+1);
1981 fprintf(handle, "*AMPLITUDE,NAME=%s\n",amp_t[j]);
1982 temp[j]=1.;
1983
1984 for(lc=1; lc<=dsNr[0]; lc++)
1985 {
1986 /* calculate the average load on that face */
1987 i=set[setNr].face[j];
1988 ipuf=0;
1989 if(face[i].type==7) ipuf=3;
1990 else if(face[i].type==8) ipuf=6;
1991 else if(face[i].type==9) ipuf=4;
1992 else if(face[i].type==10) ipuf=8;
1993 else printf(" Not supported for this element type:%d, alpha set to 0.\n",face[i].type);
1994 if(ipuf)
1995 {
1996 value=0.;
1997 for(n=0; n<ipuf; n++) value+=lcase[dsNr[lc]].dat[entity][face[i].nod[n]];
1998 value/=ipuf;
1999 }
2000 fprintf(handle, "%f, %f,\n",lcase[dsNr[lc]].value, value);
2001 }
2002 }
2003 free(dsNr);
2004 fclose(handle);
2005 }
2006 }
2007 else
2008 {
2009 for (j=0; j<set[setNr].anz_f; j++ ) temp[j]=atof(val1);
2010 }
2011
2012
2013 if((compare(val2, "ds", 2)==2)||(compare(val3, "ds", 2)==2))
2014 {
2015 if(compare(val2, "ds", 2))
2016 {
2017 lc=atoi(&val2[2])-1;
2018 entity=atoi(&val3[1])-1;
2019 }
2020 else
2021 {
2022 lc=atoi(&val3[2])-1;
2023 entity=atoi(&val4[1])-1;
2024 }
2025
2026 /* check if this lc and entity are valid */
2027 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2028 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2029
2030 /* calculate the average load on that face */
2031 for (j=0; j<set[setNr].anz_f; j++ )
2032 {
2033 i=set[setNr].face[j];
2034 alpha[j]=0.;
2035 ipuf=0;
2036 if(face[i].type==7) ipuf=3;
2037 else if(face[i].type==8) ipuf=6;
2038 else if(face[i].type==9) ipuf=4;
2039 else if(face[i].type==10) ipuf=8;
2040 else printf(" Not supported for this element type:%d, alpha set to 0.\n",face[i].type);
2041 if(ipuf)
2042 {
2043 for(n=0; n<ipuf; n++) alpha[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2044 alpha[j]/=ipuf;
2045 }
2046 }
2047 }
2048 else if((compare(val2, "sq", 2)==2)||(compare(val3, "sq", 2)==2))
2049 {
2050 /* get the range of datasets */
2051 if(compare(val2, "sq", 2))
2052 {
2053 sscanf(&val2[2],"%d-%d", &lcmin, &lcmax);
2054 entity=atoi(&val3[1])-1;
2055 }
2056 else
2057 {
2058 sscanf(&val3[2],"%d-%d", &lcmin, &lcmax);
2059 entity=atoi(&val4[1])-1;
2060 }
2061 lcmin--;
2062 lcmax--;
2063
2064 /* check if this lc and entity are valid */
2065 if((lcmin>=anz->l)||(lcmax>=anz->l)||(lcmax<=lcmin)||(lcase[lc].ncomps<entity))
2066 { printf("ERROR: ds:%d, %d or entity:%d in error\n",lcmin+1, lcmax+1, entity+1); return; }
2067
2068 printf("use lc from %d to %d of type:%s and entity:%s\n", lcmin+1, lcmax+1, lcase[lcmin].name, lcase[lcmin].compName[entity]);
2069
2070
2071 /* compile the lc-data based on a dataset-name */
2072 anz_lc=0;
2073 for(lc=lcmin; lc<=lcmax; lc++)
2074 {
2075 if( compare( lcase[lc].name, lcase[lcmin].name, strlen(lcase[lcmin].name)) == strlen(lcase[lcmin].name) )
2076 //if(compareStrings(lcase[lc].name, lcase[lcmin].name)>0)
2077 {
2078 anz_lc++;
2079 if((dsNr=(int *)realloc((int *)dsNr, (anz_lc+2) *sizeof(int)))==NULL )
2080 printf("\n\n ERROR: malloc failed \n\n") ;
2081 dsNr[anz_lc]=lc;
2082 }
2083 }
2084 if(!anz_lc)
2085 {
2086 printf(" ERROR: found no matching Dataset for string:%s\n", lcase[lcmin].name);
2087 return;
2088 }
2089 dsNr[0]=anz_lc;
2090
2091 /* check if the data of the specified lcase (Dataset) are already available */
2092 printf (" please wait, loading data\n");
2093 for(i=1; i<=dsNr[0]; i++)
2094 {
2095 lc=dsNr[i];
2096 if (!lcase[lc].loaded)
2097 {
2098 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
2099 {
2100 printf("ERROR in sendFilm: Could not read data for Dataset:%d\n", lc+1);
2101 return;
2102 }
2103 calcDatasets( lc, anz, node, lcase );
2104 recompileEntitiesInMenu(lc);
2105 }
2106 }
2107
2108 /* store the amplitudes for all faces */
2109 if ( (amp_a = (char **)malloc( (set[setNr].anz_f+1) * sizeof(char *))) == NULL )
2110 printf("\n\n ERROR: malloc failed \n\n") ;
2111
2112 /* write in abaqus-format */
2113 if (compare( format, "abq", 3)== 3)
2114 {
2115 sprintf(prognam,"%s_alfa.amp",setname);
2116 printf (" write file: %s\n", prognam );
2117 handle = fopen (prognam, "w");
2118 if ( handle== NULL )
2119 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2120 fprintf(handle, "** Film based on %s\n", setname);
2121
2122 strcpy(parameter[0], prognam);
2123 write2stack(1, parameter);
2124
2125 for (j=0; j<set[setNr].anz_f; j++ )
2126 {
2127 i=set[setNr].face[j];
2128 if ( (amp_a[j] = (char *)malloc( (MAX_LINE_LENGTH) * sizeof(char))) == NULL )
2129 printf("\n\n ERROR: malloc failed \n\n") ;
2130 sprintf(amp_a[j],"ampf_%d_%d",face[i].elem_nr, face[i].nr+1);
2131 fprintf(handle, "*AMPLITUDE,NAME=%s\n",amp_a[j]);
2132 alpha[j]=1.;
2133
2134 for(lc=1; lc<=dsNr[0]; lc++)
2135 {
2136 /* calculate the average load on that face */
2137 i=set[setNr].face[j];
2138 ipuf=0;
2139 if(face[i].type==7) ipuf=3;
2140 else if(face[i].type==8) ipuf=6;
2141 else if(face[i].type==9) ipuf=4;
2142 else if(face[i].type==10) ipuf=8;
2143 else printf(" Not supported for this element type:%d, alpha set to 0.\n",face[i].type);
2144 if(ipuf)
2145 {
2146 value=0.;
2147 for(n=0; n<ipuf; n++) value+=lcase[dsNr[lc]].dat[entity][face[i].nod[n]];
2148 value/=ipuf;
2149 }
2150 fprintf(handle, "%f, %f,\n",lcase[dsNr[lc]].value, value);
2151 }
2152 }
2153 free(dsNr);
2154 fclose(handle);
2155 }
2156 else
2157 {
2158 errMsg(" ERROR: format %s not yet supported\n", format );
2159 }
2160 }
2161 else
2162 {
2163 if((compare(val1, "ds", 2)==2)||(compare(val1, "sq", 2)==2))
2164 for (j=0; j<set[setNr].anz_f; j++ ) alpha[j]=atof(val3);
2165 else
2166 for (j=0; j<set[setNr].anz_f; j++ ) alpha[j]=atof(val2);
2167 }
2168
2169 /* write in abaqus-format */
2170 if (compare( format, "abq", 3)== 3)
2171 {
2172 if((compare(val1, "ds", 2)==2)&&(compare(val3, "ds", 2)==2)) sprintf(prognam,"%s_%s%s%s%s.flm",setname,val1,val2,val3,val4);
2173 else
2174 sprintf(prognam,"%s.flm",setname);
2175 printf (" write file: %s\n", prognam );
2176 handle = fopen (prognam, "w");
2177 if ( handle== NULL )
2178 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2179 fprintf(handle, "** Film based on %s\n", setname);
2180
2181 strcpy(parameter[0], prognam);
2182 write2stack(1, parameter);
2183
2184 for (j=0; j<set[setNr].anz_f; j++ )
2185 {
2186 i=set[setNr].face[j];
2187
2188 /* are amplitudes defined? Then we have individual values for all faces */
2189 if(amp_t!=NULL)
2190 {
2191 fprintf(handle, "*FILM, AMPLITUDE=%s, FILM AMPLITUDE=replace_with_editor\n", amp_t[j]);
2192 }
2193 else if(amp_a!=NULL)
2194 {
2195 fprintf(handle, "*FILM, AMPLITUDE=replace_with_editor, FILM AMPLITUDE=%s\n", amp_a[j]);
2196 }
2197 else if((amp_t!=NULL)&&(amp_a!=NULL))
2198 {
2199 fprintf(handle, "*FILM, AMPLITUDE=%s, FILM AMPLITUDE=%s\n", amp_t[j], amp_a[j]);
2200 }
2201
2202 if(e_enqire[face[i].elem_nr].type>6) // shell
2203 {
2204 if(e_enqire[face[i].elem_nr].type>10) // beam
2205 {
2206 if(typelabel[0]) fprintf( handle, "%d, F?%s, %d, %e\n", face[i].elem_nr, typelabel, (int)temp[j], alpha[j]);
2207 else fprintf( handle, "%d, F?%s, %lf, %e\n", face[i].elem_nr, typelabel, temp[j], alpha[j]);
2208 }
2209 else if(e_enqire[face[i].elem_nr].attr>3) // plain strain,stress or axissym
2210 {
2211 if(typelabel[0])
2212 {
2213 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, FP%s, %d, %e\n", face[i].elem_nr, typelabel, (int)temp[j], alpha[j]);
2214 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, FN%s, %d, %e\n", face[i].elem_nr, typelabel, (int)temp[j], alpha[j]);
2215 else fprintf( handle, "%d, F%d%s, %d, %e\n", face[i].elem_nr, face[i].nr-1, typelabel, (int)temp[j], alpha[j]);
2216 }
2217 else
2218 {
2219 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, FP%s, %lf, %e\n", face[i].elem_nr, typelabel, temp[j], alpha[j]);
2220 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, FN%s, %lf, %e\n", face[i].elem_nr, typelabel, temp[j], alpha[j]);
2221 else fprintf( handle, "%d, F%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr-1, typelabel, temp[j], alpha[j]);
2222 }
2223 }
2224 else
2225 {
2226 if(typelabel[0])
2227 {
2228 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, FP%s, %d, %e\n", face[i].elem_nr, typelabel, (int)temp[j], alpha[j]);
2229 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, FN%s, %d, %e\n", face[i].elem_nr, typelabel, (int)temp[j], alpha[j]);
2230 else fprintf( handle, "%d, F%d%s, %d, %e\n", face[i].elem_nr, face[i].nr+1, typelabel, (int)temp[j], alpha[j]);
2231 }
2232 else
2233 {
2234 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, FP%s, %lf, %e\n", face[i].elem_nr, typelabel, temp[j], alpha[j]);
2235 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, FN%s, %lf, %e\n", face[i].elem_nr, typelabel, temp[j], alpha[j]);
2236 else fprintf( handle, "%d, F%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr+1, typelabel, temp[j], alpha[j]);
2237 }
2238 }
2239 }
2240 else
2241 {
2242 if(typelabel[0]) fprintf( handle, "%d, F%d%s, %d, %e\n", face[i].elem_nr, face[i].nr+1, typelabel, (int)temp[j], alpha[j]);
2243 else fprintf( handle, "%d, F%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr+1, typelabel, temp[j], alpha[j]);
2244 }
2245 }
2246 fclose(handle);
2247 }
2248 else
2249 {
2250 errMsg(" ERROR: format %s not yet supported\n", format );
2251 }
2252 free(temp);
2253 free(alpha);
2254 printf (" ready\n");
2255 }
2256
2257
sendRadiate(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * val1,char * val2,char * val3,char * val4,char * val5)2258 void sendRadiate( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *val1, char *val2, char *val3, char *val4, char *val5 )
2259 {
2260 int setNr;
2261 int i,j;
2262 char prognam[MAX_LINE_LENGTH];
2263 char faceExtention[MAX_LINE_LENGTH];
2264 double *temp, *emisivity;
2265 FILE *handle;
2266 int n, lc, entity;
2267 int orif=1;
2268
2269 setNr=getSetNr(setname);
2270 if (setNr<0)
2271 {
2272 printf (" ERROR: set:%s does not exist\n", setname);
2273 return;
2274 }
2275
2276 faceExtention[0]=0;
2277 if( ((val1!=NULL)&&(val1[0]=='-'))||((val2!=NULL)&&(val2[0]=='-'))||((val3!=NULL)&&(val3[0]=='-'))||((val4!=NULL)&&(val4[0]=='-'))||((val5!=NULL)&&(val5[0]=='-')) ) orif=0;
2278
2279 if((compare(val1, "ds", 2)==2)&&(compare(val3, "ds", 2)==2)) sprintf(prognam,"%s_%s%s%s%s.rad",setname,val1,val2,val3,val4);
2280 else
2281 sprintf(prognam,"%s.rad",setname);
2282 printf (" write file: %s\n", prognam );
2283
2284 strcpy(parameter[0], prognam);
2285 write2stack(1, parameter);
2286
2287 if((temp = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
2288 printf("\n\n ERROR: malloc failure\n\n" );
2289 if((emisivity = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
2290 printf("\n\n ERROR: malloc failure\n\n" );
2291
2292 /* check if a constant value or a dataset has to be used */
2293 if(compare(val1, "ds", 2)==2)
2294 {
2295 lc=atoi(&val1[2])-1;
2296 entity=atoi(&val2[1])-1;
2297
2298 /* check if this lc and entity are valid */
2299 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2300 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2301
2302 /* check if the data of the specified lcase (Dataset) are already available */
2303 if (!lcase[lc].loaded)
2304 {
2305 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
2306 {
2307 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
2308 return;
2309 }
2310 calcDatasets( lc, anz, node, lcase );
2311 recompileEntitiesInMenu(lc);
2312 }
2313
2314 /* calculate the average load on that face */
2315 for (j=0; j<set[setNr].anz_f; j++ )
2316 {
2317 i=set[setNr].face[j];
2318 temp[j]=0.;
2319 if(face[i].type==7)
2320 {
2321 for(n=0; n<4; n++) temp[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2322 temp[j]/=4.;
2323 }
2324 else if(face[i].type==10)
2325 {
2326 for(n=0; n<8; n++) temp[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2327 temp[j]/=8.;
2328 }
2329 else
2330 {
2331 printf(" Not supported for this element type, temp set to 0.\n");
2332 temp[i]=0.;
2333 }
2334 }
2335 }
2336 else if(compare(val1, "cr", 2)==2)
2337 {
2338 strcpy(faceExtention,"CR");
2339 for (j=0; j<set[setNr].anz_f; j++ ) temp[j]=atof(&val1[2]);
2340 }
2341 else
2342 {
2343 for (j=0; j<set[setNr].anz_f; j++ ) temp[j]=atof(val1);
2344 }
2345
2346 if((compare(val2, "ds", 2)==2)||(compare(val3, "ds", 2)==2))
2347 {
2348 if(compare(val2, "ds", 2))
2349 {
2350 lc=atoi(&val2[2])-1;
2351 entity=atoi(&val3[1])-1;
2352 }
2353 else
2354 {
2355 lc=atoi(&val3[2])-1;
2356 entity=atoi(&val4[1])-1;
2357 }
2358
2359 /* check if this lc and entity are valid */
2360 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2361 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2362
2363 /* calculate the average load on that face */
2364 for (j=0; j<set[setNr].anz_f; j++ )
2365 {
2366 i=set[setNr].face[j];
2367 emisivity[j]=0.;
2368 if(face[i].type==7)
2369 {
2370 for(n=0; n<4; n++) temp[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2371 emisivity[j]/=4.;
2372 }
2373 else if(face[i].type==10)
2374 {
2375 for(n=0; n<8; n++) emisivity[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2376 emisivity[j]/=8.;
2377 }
2378 else
2379 {
2380 printf(" Not supported for this element type, emisivity set to 0.\n");
2381 emisivity[i]=0.;
2382 }
2383 }
2384 }
2385 else
2386 {
2387 if(compare(val1, "ds", 2)==2)
2388 for (j=0; j<set[setNr].anz_f; j++ ) emisivity[j]=atof(val3);
2389 else
2390 for (j=0; j<set[setNr].anz_f; j++ ) emisivity[j]=atof(val2);
2391 }
2392
2393 /* write in abaqus-format */
2394 if (compare( format, "abq", 3)== 3)
2395 {
2396 handle = fopen (prognam, "w");
2397 if ( handle== NULL )
2398 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2399 fprintf(handle, "** Radiate based on %s\n", setname);
2400 for (j=0; j<set[setNr].anz_f; j++ )
2401 {
2402 i=set[setNr].face[j];
2403 if(e_enqire[face[i].elem_nr].type>6) // shell
2404 {
2405 if(e_enqire[face[i].elem_nr].type>10) // beam
2406 fprintf( handle, "%d, R?, %lf, %e \n", face[i].elem_nr, temp[j], emisivity[j]);
2407 else if(e_enqire[face[i].elem_nr].attr>3) // plain strain,stress or axissym
2408 {
2409 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, RP%s, %lf, %e\n", face[i].elem_nr, faceExtention, temp[j], emisivity[j]);
2410 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, RN%s, %lf, %e\n", face[i].elem_nr, faceExtention, temp[j], emisivity[j]);
2411 else fprintf( handle, "%d, R%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr-1, faceExtention, temp[j], emisivity[j]);
2412 }
2413 else
2414 {
2415 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, RPOS%s, %lf, %e\n", face[i].elem_nr, faceExtention, temp[j], emisivity[j]);
2416 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, RNEG%s, %lf, %e\n", face[i].elem_nr, faceExtention, temp[j], emisivity[j]);
2417 else fprintf( handle, "%d, R%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr+1, faceExtention, temp[j], emisivity[j]);
2418 }
2419 }
2420 else fprintf( handle, "%d, R%d%s, %lf, %e\n", face[i].elem_nr, face[i].nr+1, faceExtention, temp[j], emisivity[j]);
2421 }
2422 fclose(handle);
2423 }
2424 else
2425 {
2426 errMsg(" ERROR: format %s not yet supported\n", format );
2427 }
2428 free(temp);
2429 free(emisivity);
2430 printf (" ready\n");
2431 }
2432
2433
sendDflux(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * val1,char * val2,char * val3,char type)2434 void sendDflux( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *val1, char *val2, char *val3, char type )
2435 {
2436 int setNr;
2437 int i,j;
2438 char prognam[MAX_LINE_LENGTH], label;
2439 double *load;
2440 FILE *handle;
2441 int n, lc, entity;
2442 int orif=1;
2443
2444 setNr=getSetNr(setname);
2445 if (setNr<0)
2446 {
2447 printf (" ERROR: set:%s does not exist\n", setname);
2448 return;
2449 }
2450
2451 if( ((val1!=NULL)&&(val1[0]=='-'))||((val2!=NULL)&&(val2[0]=='-'))||((val3!=NULL)&&(val3[0]=='-')) ) orif=0;
2452
2453 if(type==0)
2454 {
2455 if(compare(val1, "ds", 2)==2) sprintf(prognam,"%s_%s%s.dfl",setname,val1,val2);
2456 else
2457 sprintf(prognam,"%s.dfl",setname);
2458 }
2459 if(type==1)
2460 {
2461 if(compare(val1, "ds", 2)==2) sprintf(prognam,"%s_%s%s.mfl",setname,val1,val2);
2462 else
2463 sprintf(prognam,"%s.mfl",setname);
2464 }
2465 printf (" write file: %s\n", prognam );
2466
2467 strcpy(parameter[0], prognam);
2468 write2stack(1, parameter);
2469
2470 if((load = (double *)malloc((set[setNr].anz_f+1) * sizeof(double))) == NULL )
2471 printf("\n\n ERROR: malloc failure\n\n" );
2472
2473 /* check if a constant value or a dataset has to be used */
2474 if(compare(val1, "ds", 2)==2)
2475 {
2476 lc=atoi(&val1[2])-1;
2477 entity=atoi(&val2[1])-1;
2478
2479 /* check if this lc and entity are valid */
2480 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2481 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2482
2483 /* check if the data of the specified lcase (Dataset) are already available */
2484 if (!lcase[lc].loaded)
2485 {
2486 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
2487 {
2488 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
2489 return;
2490 }
2491 calcDatasets( lc, anz, node, lcase );
2492 recompileEntitiesInMenu(lc);
2493 }
2494
2495 /* calculate the average load on that face */
2496 for (j=0; j<set[setNr].anz_f; j++ )
2497 {
2498 i=set[setNr].face[j];
2499 load[j]=0.;
2500 if(face[i].type==7)
2501 {
2502 for(n=0; n<4; n++) load[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2503 load[j]/=4.;
2504 }
2505 else if(face[i].type==10)
2506 {
2507 for(n=0; n<8; n++) load[j]+=lcase[lc].dat[entity][face[i].nod[n]];
2508 load[j]/=8.;
2509 }
2510 else
2511 {
2512 printf(" Not supported for this element type, load set to 0.\n");
2513 load[i]=0.;
2514 }
2515 }
2516 }
2517 else
2518 {
2519 for (j=0; j<set[setNr].anz_f; j++ ) load[j]=atof(val1);
2520 }
2521
2522 /* write in abaqus-format */
2523 if (compare( format, "abq", 3)== 3)
2524 {
2525 handle = fopen (prognam, "w");
2526 if ( handle== NULL )
2527 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2528 if(type==0) { fprintf(handle, "** DFlux based on %s\n", setname); label='S'; }
2529 if(type==1) { fprintf(handle, "** MASSFLOW based on %s\n", setname); label='M'; }
2530 for (j=0; j<set[setNr].anz_f; j++ )
2531 {
2532 i=set[setNr].face[j];
2533 if(e_enqire[face[i].elem_nr].type>6) // shell
2534 {
2535 if(e_enqire[face[i].elem_nr].type>10) // beam
2536 fprintf( handle, "%d, %c?, %e\n", face[i].elem_nr, label, load[j]);
2537 else if(e_enqire[face[i].elem_nr].attr>3) // plain strain,stress or axissym
2538 {
2539 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, %cP, %e\n", face[i].elem_nr, label, load[j]);
2540 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, %cN, %e\n", face[i].elem_nr, label, load[j]);
2541 else fprintf( handle, "%d, %c%d, %e\n", face[i].elem_nr, label, face[i].nr-1, load[j]);
2542 }
2543 else
2544 {
2545 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, %cPOS, %e\n", face[i].elem_nr, label, load[j]);
2546 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, %cNEG, %e\n", face[i].elem_nr, label, load[j]);
2547 else fprintf( handle, "%d, %c%d, %e\n", face[i].elem_nr, label, face[i].nr-1, load[j]);
2548 }
2549 }
2550 else fprintf( handle, "%d, %c%d, %e\n", face[i].elem_nr, label, face[i].nr+1, load[j]);
2551 }
2552 fclose(handle);
2553 }
2554 else
2555 {
2556 errMsg(" ERROR: format %s not yet supported\n", format );
2557 }
2558 free(load);
2559 printf (" ready\n");
2560 }
2561
2562
sendSPCF(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * dofstring,char * val1,char * val2,char * val3)2563 void sendSPCF( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *dofstring, char *val1, char *val2, char *val3 )
2564 {
2565 int length,i, dofi;
2566 char dofa[2]={" \0"};
2567 char buffer[MAX_LINE_LENGTH];
2568
2569 if(val1==NULL)
2570 {
2571 printf (" ERROR: no value specified\n");
2572 return;
2573 }
2574 if(strlen(val1)==0)
2575 {
2576 printf (" ERROR: no value specified\n");
2577 return;
2578 }
2579
2580 length=strlen( dofstring );
2581 for (i=0; i<length; i++)
2582 {
2583 dofa[0]=dofstring[i];
2584 if(checkIfNumber(dofa)) dofi=atoi(dofa); else dofi=-1;
2585 if ((dofstring[i]!='t')&&(dofstring[i]!='p')&&((dofi<0)||(dofi>6))) { errMsg ("ERROR dof:%s not known\n", dofa); return; }
2586 else
2587 {
2588 if(dofstring[i]=='t') sprintf(buffer,"%d",DOFT);
2589 else if(dofstring[i]=='p') sprintf(buffer,"%d",DOFP);
2590 else sprintf(buffer,"%c",dofstring[i]);
2591 sendPressure( setname, format, anz, node, e_enqire, val1, val2, val3, buffer );
2592 }
2593 }
2594 }
2595
2596
sendSPC(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * dofstring,char * val1,char * val2,char * val3)2597 void sendSPC( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *dofstring, char *val1, char *val2, char *val3 )
2598 {
2599 int setNr;
2600 int length,i,j,n, dofi, lc, entity;
2601 char prognam[MAX_LINE_LENGTH], dofa[2]={" \0"};
2602 Nodes *norm;
2603 int *sum_n;
2604 double fx=0.,fy=0.,fz=0.;
2605 FILE *handle;
2606
2607
2608 setNr=getSetNr(setname);
2609 if (setNr<0)
2610 {
2611 printf (" ERROR: set:%s does not exist\n", setname);
2612 return;
2613 }
2614
2615 sprintf(prognam,"%s_%s%s%s%s.bou",setname,dofstring,val1,val2,val3);
2616 //sprintf(prognam,"%s.bou",setname);
2617 printf (" write file: %s\n", prognam );
2618
2619 strcpy(parameter[0], prognam);
2620 write2stack(1, parameter);
2621
2622 handle = fopen (prognam, "w");
2623 if ( handle== NULL )
2624 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2625 if (compare( format, "abq", 3)== 3)
2626 {
2627 fprintf(handle, "** BOUNDARY based on %s\n", setname);
2628 }
2629 else if (compare( format, "ans", 3)== 3)
2630 {
2631 fprintf(handle, "! BOUNDARY based on %s\n", setname);
2632 }
2633 else if (compare( format, "nas", 3)== 3)
2634 {
2635 fprintf(handle, "$ BOUNDARY based on %s\n", setname);
2636 }
2637 else
2638 {
2639 fclose(handle);
2640 errMsg(" ERROR: format %s not yet supported\n", format );
2641 return;
2642 }
2643
2644 /* move the nodes normal to the surface (xyz can have individual factors) */
2645 if(compare(dofstring, "nor", 2)==2)
2646 {
2647 /* ---- add the nodes and faces ----- */
2648 if(!set[setNr].anz_f)
2649 {
2650 printf(" WARNING: Found no faces in set:%s. A 'comp %s down' was performed\n",set[setNr].name,set[setNr].name);
2651 completeSet( set[setNr].name, "do" );
2652 }
2653
2654 /* calculate the average normal on every node */
2655 getNodeNormalen(&sum_n, &norm, setNr, anz, face);
2656
2657 /* check if a constant dofstring or a dataset has to be used */
2658 if(compare(val1, "ds", 2)==2)
2659 {
2660 if((!val1[2])&&(!val2[1])) { printf("ERROR: ds and/or entity not defined\n"); return; }
2661 lc=atoi(&val1[2])-1;
2662 entity=atoi(&val2[1])-1;
2663
2664 /* check if this lc and entity are valid */
2665 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2666 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2667
2668 /* check if the data of the specified lcase (Dataset) are already available */
2669 if (!lcase[lc].loaded)
2670 {
2671 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
2672 {
2673 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
2674 return;
2675 }
2676 calcDatasets( lc, anz, node, lcase );
2677 recompileEntitiesInMenu(lc);
2678 }
2679
2680 for (n=1; n<=anz->nmax; n++ )
2681 {
2682 if( sum_n[n] >0 )
2683 {
2684 fx=lcase[lc].dat[entity][n];
2685 if (compare( format, "abq", 3)== 3)
2686 {
2687 fprintf(handle, "%d, 1, 1, %f\n",n, fx* norm[n].nx );
2688 fprintf(handle, "%d, 2, 2, %f\n",n, fx* norm[n].ny );
2689 fprintf(handle, "%d, 3, 3, %f\n",n, fx* norm[n].nz );
2690 }
2691 if (compare( format, "ans", 3)== 3)
2692 {
2693 fprintf(handle, "D,%d, UX, %f\n",n, fx* norm[n].nx );
2694 fprintf(handle, "D,%d, UY, %f\n",n, fx* norm[n].ny );
2695 fprintf(handle, "D,%d, UZ, %f\n",n, fx* norm[n].nz );
2696 }
2697 // nas: no forced deflections supported
2698 }
2699 }
2700 }
2701 else
2702 {
2703 if((strlen(val2)==0)&&(strlen(val3)==0)) fx=fy=fz=atof(val1);
2704 else
2705 {
2706 fx=atof(val1);
2707 fy=atof(val2);
2708 fz=atof(val3);
2709 }
2710 //printf("normal deflection:%f %f %f\n",fx,fy,fz);
2711 for (n=1; n<=anz->nmax; n++ )
2712 {
2713 if( sum_n[n] >0 )
2714 {
2715 if (compare( format, "abq", 3)== 3)
2716 {
2717 fprintf(handle, "%d, 1, 1, %f\n",n, fx* norm[n].nx );
2718 fprintf(handle, "%d, 2, 2, %f\n",n, fy* norm[n].ny );
2719 fprintf(handle, "%d, 3, 3, %f\n",n, fz* norm[n].nz );
2720 }
2721 if (compare( format, "ans", 3)== 3)
2722 {
2723 fprintf(handle, "D,%d, UX, %f\n",n, fx* norm[n].nx );
2724 fprintf(handle, "D,%d, UY, %f\n",n, fy* norm[n].ny );
2725 fprintf(handle, "D,%d, UZ, %f\n",n, fz* norm[n].nz );
2726 }
2727 // nas: no forced deflections supported
2728 }
2729 }
2730 }
2731 }
2732 else
2733 {
2734 length=strlen( dofstring );
2735 for (i=0; i<length; i++)
2736 {
2737 dofa[0]=dofstring[i];
2738 if(checkIfNumber(dofa)) dofi=atoi(dofa); else dofi=-1;
2739 if ((dofstring[i]!='t')&&(dofstring[i]!='p')&&((dofi<0)||(dofi>6))) { errMsg ("ERROR dof:%s not known\n", dofa); return; }
2740 else
2741 {
2742 /* check if a constant dofstring or a dataset has to be used */
2743 if(compare(val1, "ds", 2)==2)
2744 {
2745 if(!val1[2]) { printf("ERROR: ds not defined\n"); return; }
2746 lc=atoi(&val1[2])-1;
2747 if(val2[1]) entity=atoi(&val2[1])-1;
2748 else entity=0;
2749
2750 /* check if this lc and entity are valid */
2751 if((lc>=anz->l)||(lcase[lc].ncomps<entity))
2752 { printf("ERROR: ds:%d or entity:%d not defined\n",lc,entity); return; }
2753
2754 /* check if the data of the specified lcase (Dataset) are already available */
2755 if (!lcase[lc].loaded)
2756 {
2757 if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
2758 {
2759 printf(" ERROR in sendSet: Could not read data for Dataset:%d\n", lc+1);
2760 return;
2761 }
2762 calcDatasets( lc, anz, node, lcase );
2763 recompileEntitiesInMenu(lc);
2764 }
2765
2766 for (j=0; j<set[setNr].anz_n; j++ )
2767 {
2768 if (compare( format, "abq", 3)== 3)
2769 {
2770 if( dofstring[i]=='t') fprintf(handle, "%d, %d, , %e\n",set[setNr].node[j], DOFT, lcase[lc].dat[entity][set[setNr].node[j]] );
2771 else if( dofstring[i]=='p') fprintf(handle, "%d, %d, , %e\n",set[setNr].node[j], DOFP, lcase[lc].dat[entity][set[setNr].node[j]] );
2772 else fprintf(handle, "%d, %c, , %e\n",set[setNr].node[j], dofstring[i], lcase[lc].dat[entity][set[setNr].node[j]] );
2773 }
2774 else if (compare( format, "ans", 3)== 3)
2775 {
2776 if (dofi==1) fprintf(handle, "D,%d, UX, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2777 if (dofi==2) fprintf(handle, "D,%d, UY, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2778 if (dofi==3) fprintf(handle, "D,%d, UZ, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2779 if (dofi==4) fprintf(handle, "D,%d, ROTX, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2780 if (dofi==5) fprintf(handle, "D,%d, ROTY, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2781 if (dofi==6) fprintf(handle, "D,%d, ROTZ, %e\n",set[setNr].node[j], lcase[lc].dat[entity][set[setNr].node[j]]);
2782 }
2783 // nas: no forced deflections supported
2784 }
2785 }
2786 else
2787 {
2788 for (j=0; j<set[setNr].anz_n; j++ )
2789 {
2790 if (compare( format, "abq", 3)== 3)
2791 {
2792 if( dofstring[i]=='t') fprintf(handle, "%d, %d, , %s\n",set[setNr].node[j], DOFT, val1 );
2793 else if( dofstring[i]=='p') fprintf(handle, "%d, %d, , %s\n",set[setNr].node[j], DOFP, val1 );
2794 else fprintf(handle, "%d, %c, , %s\n",set[setNr].node[j], dofstring[i], val1 );
2795 }
2796 else if (compare( format, "ans", 3)== 3)
2797 {
2798 if (dofi==1) fprintf(handle, "D,%d, UX, %s\n",set[setNr].node[j], val1 );
2799 if (dofi==2) fprintf(handle, "D,%d, UY, %s\n",set[setNr].node[j], val1 );
2800 if (dofi==3) fprintf(handle, "D,%d, UZ, %s\n",set[setNr].node[j], val1 );
2801 if (dofi==4) fprintf(handle, "D,%d, ROTX, %s\n",set[setNr].node[j], val1 );
2802 if (dofi==5) fprintf(handle, "D,%d, ROTY, %s\n",set[setNr].node[j], val1 );
2803 if (dofi==6) fprintf(handle, "D,%d, ROTZ, %s\n",set[setNr].node[j], val1 );
2804 }
2805 // nas: no forced deflections supported
2806 else if (compare( format, "nas", 3)== 3)
2807 {
2808 fprintf(handle, "SPC1, 1,%8d,%8d\n", dofi, set[setNr].node[j]);
2809 }
2810 }
2811 }
2812 }
2813 }
2814 }
2815 fclose(handle);
2816 printf (" ready\n");
2817 }
2818
2819
sendCflux(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * dofstring,char * val2)2820 void sendCflux( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *dofstring, char *val2 )
2821 {
2822 int setNr;
2823 int length, i,j, dofi=0;
2824 char prognam[MAX_LINE_LENGTH];
2825
2826 FILE *handle;
2827
2828
2829 setNr=getSetNr(setname);
2830 if (setNr<0)
2831 {
2832 printf (" ERROR: set:%s does not exist\n", setname);
2833 return;
2834 }
2835
2836 sprintf(prognam,"%s.cfl",setname);
2837 printf (" write file: %s\n", prognam );
2838
2839 strcpy(parameter[0], prognam);
2840 write2stack(1, parameter);
2841
2842 if (compare( format, "abq", 3)== 3)
2843 {
2844 handle = fopen (prognam, "w");
2845 if ( handle== NULL )
2846 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2847 fprintf(handle, "** Cflux based on %s\n", setname);
2848 length=strlen( dofstring );
2849 for (i=0; i<length; i++)
2850 {
2851 if (dofstring[i]!='t') errMsg ("ERROR dof:%d not known\n", dofi);
2852 else
2853 {
2854 for (j=0; j<set[setNr].anz_n; j++ )
2855 {
2856 fprintf(handle, "%d, %d, %s\n",set[setNr].node[j], DOFT, val2 );
2857 }
2858 }
2859 }
2860 fclose(handle);
2861 }
2862 else
2863 {
2864 errMsg(" ERROR: format %s not yet supported\n", format );
2865 }
2866 printf (" ready\n");
2867 }
2868
2869
sendForce(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,double * f)2870 void sendForce( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, double *f )
2871 {
2872 int setNr;
2873 int i,j;
2874 char prognam[MAX_LINE_LENGTH];
2875
2876 FILE *handle;
2877
2878
2879 setNr=getSetNr(setname);
2880 if (setNr<0)
2881 {
2882 printf (" ERROR: set:%s does not exist\n", setname);
2883 return;
2884 }
2885
2886 sprintf (prognam, "%s.frc",setname);
2887 printf (" write file: %s\n", prognam );
2888
2889 strcpy(parameter[0], prognam);
2890 write2stack(1, parameter);
2891
2892 if (compare( format, "abq", 3)== 3)
2893 {
2894 handle = fopen (prognam, "w");
2895 if ( handle== NULL )
2896 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2897 fprintf(handle, "** Forces based on %s\n", setname );
2898 for (j=0; j<set[setNr].anz_n; j++ )
2899 {
2900 for (i=0; i<3; i++)
2901 {
2902 if(f[i]) fprintf(handle, "%d, %d, %lf\n",set[setNr].node[j], i+1, f[i] );
2903 }
2904 }
2905 fclose(handle);
2906 }
2907 else if (compare( format, "ans", 3)== 3)
2908 {
2909 handle = fopen (prognam, "w");
2910 if ( handle== NULL )
2911 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2912 fprintf(handle, "! Forces based on %s\n", setname );
2913 for (j=0; j<set[setNr].anz_n; j++ )
2914 {
2915 if(f[0]) fprintf(handle, "F, %d, FX, %lf\n",set[setNr].node[j], f[0] );
2916 if(f[1]) fprintf(handle, "F, %d, FY, %lf\n",set[setNr].node[j], f[1] );
2917 if(f[2]) fprintf(handle, "F, %d, FZ, %lf\n",set[setNr].node[j], f[2] );
2918 }
2919 fclose(handle);
2920 }
2921 else if (compare( format, "nas", 3)== 3)
2922 {
2923 handle = fopen (prognam, "w");
2924 if ( handle== NULL )
2925 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2926 fprintf(handle, "$ Forces based on %s\n", setname );
2927 for (j=0; j<set[setNr].anz_n; j++ )
2928 {
2929 fprintf(handle, "FORCE, 1,%8d,%8d,%12.5e,%12.5e,%12.5e,%12.5e\n", set[setNr].node[j],0,1.,f[0],f[1],f[2]);
2930 }
2931 fclose(handle);
2932 }
2933 else
2934 {
2935 errMsg(" ERROR: format %s not yet supported\n", format );
2936 }
2937 printf (" ready\n");
2938 }
2939
2940
sendNames(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire)2941 void sendNames( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire )
2942 {
2943 int i,j=0,e,incr=0;
2944 int setNr, nf=0;
2945 char prognam[MAX_LINE_LENGTH];
2946
2947 FILE *handle;
2948 FILE *handle_pat;
2949
2950
2951 setNr=getSetNr(setname);
2952 if (setNr<0)
2953 {
2954 printf (" ERROR: set:%s does not exist\n", setname);
2955 return;
2956 }
2957 sprintf(prognam, "%s.nam", setname);
2958 printf (" write file: %s\n", prognam );
2959
2960 strcpy(parameter[0], prognam);
2961 write2stack(1, parameter);
2962
2963 if (compare( format, "raw", 3)== 3)
2964 {
2965 if((set[setNr].anz_n>0)&&(set[setNr].anz_e>0))
2966 {
2967 sprintf(parameter[0]," ERROR: The set includes nodes and elements, this is not permitted in 'raw' mode\n");
2968 printf("%s",parameter[0]);
2969 write2stack(1, parameter);
2970 return;
2971 }
2972 handle = fopen (prognam, "w");
2973 if ( handle== NULL )
2974 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2975 if (set[setNr].anz_n>0)
2976 {
2977 fprintf(handle, "** Nodes from set %s\n", setname);
2978 for (j=0; j<set[setNr].anz_n; j++ )
2979 {
2980 fprintf(handle, "%d, \n",set[setNr].node[j] );
2981 }
2982 }
2983 if (set[setNr].anz_e>0)
2984 {
2985 fprintf(handle, "** Elements from set %s\n", setname);
2986 for (j=0; j<set[setNr].anz_e; j++ )
2987 {
2988 fprintf(handle, "%d, \n",set[setNr].elem[j] );
2989 }
2990 }
2991 fclose(handle);
2992 }
2993 else if (compare( format, "abq", 3)== 3)
2994 {
2995 handle = fopen (prognam, "w");
2996 if ( handle== NULL )
2997 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
2998 fprintf(handle, "** Names based on %s\n", setname );
2999 if (set[setNr].anz_n>0)
3000 {
3001 fprintf(handle, "*NSET,NSET=N%s \n",set[setNr].name );
3002 for (j=0; j<set[setNr].anz_n; j++ )
3003 {
3004 fprintf(handle, "%d, \n",set[setNr].node[j] );
3005 }
3006 }
3007 if (set[setNr].anz_e>0)
3008 {
3009 fprintf(handle, "*ELSET,ELSET=E%s \n",set[setNr].name );
3010 for (j=0; j<set[setNr].anz_e; j++ )
3011 {
3012 fprintf(handle, "%d, \n",set[setNr].elem[j] );
3013 }
3014 }
3015 fclose(handle);
3016 }
3017 else if (compare( format, "ans", 3)== 3)
3018 {
3019 handle = fopen (prognam, "w");
3020 if ( handle== NULL )
3021 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
3022 fprintf(handle, "! Names based on %s\n", setname );
3023 if (set[setNr].anz_n>0)
3024 {
3025 fprintf(handle, "NSEL, NONE \n");
3026 fprintf(handle, "NSEL, S, NODE, , %d \n",set[setNr].node[0]);
3027 for (j=1; j<set[setNr].anz_n; j++ )
3028 {
3029 fprintf(handle, "NSEL, A, NODE, , %d \n",set[setNr].node[j]);
3030 }
3031 fprintf(handle, "CM, %s, NODE \n",set[setNr].name);
3032 fprintf(handle, "NSEL, ALL \n");
3033 }
3034 if (set[setNr].anz_e>0)
3035 {
3036 fprintf(handle, "ESEL, NONE \n");
3037 fprintf(handle, "ESEL, S, ELEM, , %d \n",set[setNr].elem[0]);
3038 for (j=1; j<set[setNr].anz_e; j++ )
3039 {
3040 fprintf(handle, "ESEL, A, ELEM, , %d \n",set[setNr].elem[j]);
3041 }
3042 fprintf(handle, "CM, %s, ELEM \n",set[setNr].name);
3043 fprintf(handle, "ESEL, ALL \n");
3044 }
3045 fclose(handle);
3046 }
3047 /* interface to code_aster from Paul CARRICO */
3048 else if (compare( format, "ast", 3)== 3)
3049 {
3050 handle = fopen (prognam, "w");
3051 if ( handle== NULL )
3052 {
3053 printf ("\nThe input file %s could not be opened.\n\n", prognam);
3054 return;
3055 }
3056 if (set[setNr].anz_n>0)
3057 {
3058 fprintf(handle, "GROUP_NO\n%s\n",set[setNr].name);
3059 for (j=0; j<set[setNr].anz_n; j++ )
3060 {
3061 fprintf(handle, "N%d ",set[setNr].node[j]);
3062 incr++;
3063 if (incr == 8)
3064 {
3065 fprintf(handle, "\n");
3066 incr = 0;
3067 }
3068 }
3069 if (incr != 0) fprintf(handle, "\n");
3070 fprintf(handle, "FINSF\n");
3071 }
3072 if (set[setNr].anz_e>0)
3073 {
3074 fprintf(handle, "GROUP_MA\n");
3075 fprintf(handle, "%s\n",set[setNr].name );
3076 incr = 0;
3077 for (j=0; j<set[setNr].anz_e; j++ )
3078 {
3079 fprintf(handle, "M%d ",set[setNr].elem[j] );
3080 incr++;
3081 if (incr == 8)
3082 {
3083 fprintf(handle, "\n");
3084 incr = 0;
3085 }
3086 }
3087 if (incr != 0) fprintf(handle, "\n");
3088 fprintf(handle, "FINSF\n");
3089 }
3090 fclose(handle);
3091 }
3092 /* interface to Samcef/Bacon from Paul CARRICO */
3093 else if (compare( format, "sam", 3)== 3)
3094 {
3095 handle = fopen (prognam, "w");
3096 if ( handle== NULL )
3097 {
3098 printf ("\nThe input file %s could not be opened.\n\n", prognam);
3099 return;
3100 }
3101 if (set[setNr].anz_n>0)
3102 {
3103 fprintf(handle, ".SEL GROUPE \"%s\" NOEUDS\n",set[setNr].name);
3104 for (j=0; j<set[setNr].anz_n; j++ )
3105 {
3106 fprintf(handle, " I %d\n",set[setNr].node[j]);
3107 }
3108 }
3109 if (set[setNr].anz_e>0)
3110 {
3111 fprintf(handle, ".SEL GROUPE \"%s\" MAILLES\n",set[setNr].name);
3112 for (j=0; j<set[setNr].anz_e; j++ )
3113 {
3114 fprintf(handle, " I %d\n",set[setNr].elem[j] );
3115 }
3116 }
3117 fclose(handle);
3118 }
3119 /* interface to gagemap */
3120 else if (compare( format, "gmp", 3)== 3)
3121 {
3122 handle = fopen (prognam, "w");
3123 if ( handle== NULL )
3124 {
3125 printf ("\nThe input file %s could not be opened.\n\n", prognam);
3126 return;
3127 }
3128 if (set[setNr].anz_n>0)
3129 {
3130 fprintf(handle, "\n**Group_Start**\n");
3131 fprintf(handle, "Name= %s\n",set[setNr].name);
3132 fprintf(handle, "Opcode= 0\n");
3133 fprintf(handle, "Type= 0\n");
3134 fprintf(handle, "Color= 255 0 0\n");
3135 fprintf(handle, "Nodetype= 0\n");
3136 fprintf(handle, "Nodes= \n");
3137 for (j=0; j<set[setNr].anz_n; j++ )
3138 {
3139 fprintf(handle, "%d\n",set[setNr].node[j]);
3140 }
3141 }
3142 fclose(handle);
3143 }
3144 /* patran neutral file */
3145 else if (compare( format, "pat", 3)== 3)
3146 {
3147 handle = fopen (prognam, "w");
3148 if ( handle== NULL )
3149 {
3150 printf ("\nThe input file %s could not be opened.\n\n", prognam);
3151 return;
3152 }
3153 handle_pat = fopen ("trailer.out", "w");
3154 if ( handle_pat== NULL )
3155 {
3156 printf ("\nThe trailer file could not be opened.\n\n");
3157 return;
3158 }
3159 printf(" patran neutral file for set:%s will be written, bundle all .nam to .out before reading and add the 'trailer.out'\n", set[setNr].name);
3160
3161 fprintf(handle, "21%8d%8d%8d\n", setNr+2, (set[setNr].anz_n+set[setNr].anz_e)*2, (int)(1+((set[setNr].anz_n+set[setNr].anz_e)*2+9)/10));
3162 //if(strlen(set[setNr].name)<=12) j=strlen(set[setNr].name); else j=12;
3163 //for(i=0; i<j; i++) buffer[i]=set[setNr].name[i];
3164 //for( ; i<12; i++) buffer[i]=' '; buffer[i]=0;
3165 //fprintf(handle, "%s\n", buffer);
3166 fprintf(handle, "%s\n", set[setNr].name);
3167 j=0;
3168 if (set[setNr].anz_n>0)
3169 {
3170 for (i=0; i<set[setNr].anz_n; i++ )
3171 {
3172 fprintf(handle, "%8d%8d",(int)5,set[setNr].node[i]);
3173 j++;
3174 if(!(j%5)) fprintf(handle, "\n");
3175 }
3176 }
3177 if (set[setNr].anz_e>0)
3178 {
3179 for (i=0; i<set[setNr].anz_e; i++ )
3180 {
3181 e=set[setNr].elem[i];
3182 if (e_enqire[e].type == 1) nf=12; /* HEXA8 */
3183 else if (e_enqire[e].type == 2) nf=11; /* PENTA6 */
3184 else if (e_enqire[e].type == 3) nf=9; /* TET4 */
3185 else if (e_enqire[e].type == 4) nf=12; /* HEXA20 */
3186 else if (e_enqire[e].type == 5) nf=11; /* PENTA15 */
3187 else if (e_enqire[e].type == 6) nf= 9; /* TET10 */
3188 else if (e_enqire[e].type == 7) nf=7; /* TRI3 */
3189 else if (e_enqire[e].type == 8) nf=7; /* TRI6 */
3190 else if (e_enqire[e].type == 9) nf=8; /* QUAD4 */
3191 else if (e_enqire[e].type == 10) nf=8; /* QUAD8 */
3192 else if (e_enqire[e].type == 11) nf=6; /* BEAM */
3193 else if (e_enqire[e].type == 12) nf=6; /* BEAM3 */
3194
3195 fprintf(handle, "%8d%8d",nf,set[setNr].elem[i] );
3196 j++;
3197 if(!(j%5)) fprintf(handle, "\n");
3198 }
3199 }
3200 if(j%5) fprintf(handle, "\n");
3201 fprintf(handle_pat, "99 0 0 1 0 0 0 0 0\n");
3202 fclose(handle_pat);
3203 fclose(handle);
3204 }
3205
3206 else
3207 {
3208 errMsg(" ERROR: format %s not yet supported\n", format );
3209 }
3210 printf (" ready\n");
3211 }
3212
3213
3214
sendSurfaces(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,char * val)3215 void sendSurfaces( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, char *val )
3216 {
3217 int i,j;
3218 int setNr;
3219 char prognam[MAX_LINE_LENGTH];
3220 int orif=1;
3221
3222 FILE *handle;
3223
3224
3225 setNr=getSetNr(setname);
3226 if (setNr<0)
3227 {
3228 printf (" ERROR: set:%s does not exist\n", setname);
3229 return;
3230 }
3231
3232 if((val!=NULL)&&(val[0]=='-')) orif=0;
3233
3234 sprintf(prognam, "%s.sur", setname);
3235 printf (" write file: %s\n", prognam );
3236
3237 strcpy(parameter[0], prognam);
3238 write2stack(1, parameter);
3239
3240 if ((compare( format, "abq", 3)== 3)||(compare( format, "raw", 3)== 3))
3241 {
3242 handle = fopen (prognam, "w");
3243 if ( handle== NULL )
3244 { printf ("\nThe input file %s could not be opened.\n\n", prognam); return; }
3245 fprintf(handle, "** Surfaces based on %s\n", setname );
3246 if(compare( format, "raw", 3)== 3);
3247 else
3248 {
3249 fprintf(handle, "*SURFACE, NAME=S%s\n", setname );
3250 }
3251 if (set[setNr].anz_f>0)
3252 {
3253 for (j=0; j<set[setNr].anz_f; j++ )
3254 {
3255 i=set[setNr].face[j];
3256 if(e_enqire[face[i].elem_nr].type>6) // shell
3257 {
3258 if(e_enqire[face[i].elem_nr].type>10) // beam
3259 fprintf( handle, "%d, S?\n", face[i].elem_nr);
3260 else if(e_enqire[face[i].elem_nr].attr>3) // plain strain,stress or axissym
3261 {
3262 //if(face[i].nr==0) fprintf( handle, "%d, SN\n", face[i].elem_nr);
3263 //else if(face[i].nr==1) fprintf( handle, "%d, SP\n", face[i].elem_nr);
3264 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, SP \n", face[i].elem_nr);
3265 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, SN \n", face[i].elem_nr);
3266 else fprintf( handle, "%d, S%d\n", face[i].elem_nr, face[i].nr-1);
3267 }
3268 else
3269 {
3270 //if(face[i].nr==0) fprintf( handle, "%d, SNEG\n", face[i].elem_nr);
3271 //else if(face[i].nr==1) fprintf( handle, "%d, SPOS\n", face[i].elem_nr);
3272 if((face[i].nr==1)&&(orif==1)) fprintf( handle, "%d, SPOS \n", face[i].elem_nr);
3273 else if((face[i].nr==1)&&(orif==0)) fprintf( handle, "%d, SNEG \n", face[i].elem_nr);
3274 else fprintf( handle, "%d, S%d\n", face[i].elem_nr, face[i].nr+1);
3275 }
3276 }
3277 else fprintf( handle, "%d, S%d\n", face[i].elem_nr, face[i].nr+1);
3278 }
3279 }
3280 fclose(handle);
3281 }
3282 else
3283 {
3284 errMsg(" ERROR: format %s not yet supported\n", format );
3285 }
3286 printf (" ready\n");
3287 }
3288
3289
3290
3291