-
Notifications
You must be signed in to change notification settings - Fork 4
/
unical1d.c
1396 lines (1256 loc) · 59.4 KB
/
unical1d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* UNIVERSAL - CalculiX interface program, Bernhardi, Aug 2011 */
/****************************************************************************
* THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
* IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE
* AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
*
* THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
* WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
* LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
*
* YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
* ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION, INC,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*****************************************************************************/
/*
This small program converts finite elemet meshes given in the SDRL universal
file format into ABAQUS / Calculix compatible input decks. The format
of the universal data sets can be found at http://www.sdrl.uc.edu.
The element - node mapping is taken from the Python unv2abaqus script, which
can be found at /www.caelinux.org.
This program will still be far from being error - free; therefore, use
it with caution!
The program also translates surface meshes in case they are present in
the .med file: If the main mesh is planar, the line elements (if they
exist) are translated to abaqus elsets with load surface IDs P1...P4.
Correspondingly, if a volume mesh is given, the surface meshes (if they
are also present in the med file) are converted to elsets with load
IDs P1...P6.
The *elset names will be the same as the group names defined in SALOME.
I use that feature to introduce boundary conditions. However, the
calculation of the surface elsets takes quite long for very large meshes.
The program works for all CalculiX element types. It compiles under
opensuse 12.3 (but should compile on all linuxes).
To install and use:
- place the program source text into a proper directory, e.g. /path/unical
- go to that directory.
- issue a "gcc -o2 -static -o unical unical2.c" command.
- try it out using, for example, a universal file cube.unv:
"/path/unical cube".
- Then, configure your Abaqus/Calculix analysis run by modifying the
cube.inp file: Introduction of loads, boundary conditions, prodedures,
etc.
Remarks:
- Unical translates the following three Universal data sets:
2411, node point numbers and coordinates
2412, element type codes and connectivities
2467, groups of nodes and elements.
Everything else is ignored.
- Only tested with universal files generated by SALOME.
- Planar elements are always translated to shell elements, e.g. S8R. Thus
the *element, type= lines must be modified if e.g. CPS8 elements are to be
used.
- In case of a volume mesh, SALOME also generates surface elements;
correspondingly, in case of a planar mesh the boundary is also output
using line elements. In most cases the boundaries are not needed and
are therefore not translated to CalculiX; rather, the surface elements
are used to generate *surface input lines for ease of boundary condition
definition, as described above.
- However, there are cases where different element dimensions are desired;
for example, combination of volume elements and beam elements. If this is the
case, specify "./unical -f cube". Then, all elements are translated. If only
volumes and beams are wanted, shell elements must be manually removed from
the .inp file.
- Beam orientations are not treated yet.
=========================================================================*/
#define PROOL 1 // DIRTY EXPERIMENTAL!!! modification by prool: alternative output format.
// Prool here: http://prool.kharkov.org http://calculix.kharkov.org <proolix@gmail.com>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h> // add by prool
void exitif(); /* return error message and exit. */
void countuni(); /* count number of nodes and elements. */
void allocate(); /* allocate large data arrays. */
void readnodes(); /* read node point data from .unv file. */
void readelements(); /* read element connectivities from .unv file. */
void readgroups(); /* read group information. */
void writemesh(); /* write mesh data to med file. */
void surface(); /* generate and write surfaces. */
FILE *fid=0; /* UNIVERSAL mesh file. */
char inname[200]; /* input file name: .unv file. */
char outname[200]; /* output file name: .inp file. */
char problem[200]; /* problem name. */
int full; /* full.eq.0; only elements with dimension less than */
/* max dimension are converted; full.eq.1, all elements. */
int ret; /* return key. */
char *sret; /* return key for fgets(). */
char line[201]; /* this holds one input line. */
char name[101]; /* name of dataset. */
int maxline=200; /* max 100 characters in one input line. */
int key; /* .unv file record key. */
int node; /* node counter. */
int element; /* element counter. */
int maxnode; /* total number of nodes. */
int maxele[16]; /* total number of elements for each type. */
int sumele; /* total number of all elements. */
int numnode; /* current number of node. */
int numvol; /* number of elements with dim=maxdimen. */
int numele; /* current number of element. */
int elnumber[16]; /* number of elements for each type. */
int *nodenumbers; /* nope point numbers; sorted. */
double *coords; /* node point coordinates. */
int *elnumbers[16]; /* element numbers. */
int *elem[16]; /* element connectivity. */
double x,y,z; /* node coordinates. */
int n[101]; /* nodes at current element. */
int eltype; /* type of current element (internal). */
int utype; /* type of element, universal file. */
int btype; /* beam or non-beam element */
int dummy; /* nothing. */
int elnode[50]; /* numbers of nodes at current element. */
int nc,nc1; /* counts nodes during reading of elements. */
int i,j,k; /* loop counters. */
char groupname[101]; /* group name. */
int groupnumber; /* group number. */
int nument; /* number of entities in current group. */
int maxgroup; /* total number of groups on dataset. */
int numgroup; /* current group number. */
int *groupents; /* lengths of all groups. */
int *groupnumbers; /* stores all group numbers. */
char **groupnames; /* stores all group names. */
int **groupmembers; /* stores all group members (elem/node numbers). */
int **grouptypes; /* types of group members (1=elem, 2=node). */
int **grouppointers; /* pointers to connectivity of elements in groups. */
int **groupeltypes; /* types of elements in groups. */
/* a plane element listed in surfnum corresponds to
a volume element listed in volelnum and a surface number
(1-6, listed in facenum) of that volume element. */
int *surfnum; /* surface element number. */
int *volelnum; /* volume element number. */
int *facenum; /* face number of volume element. */
int *group; /* group number of surface element. */
int eltypes[87][3]={
0, 0, 0, /* empty. */
11, 11, 1, /* Rod */
11, 21, 1, /* Linear beam */
12, 22, 1, /* Tapered beam */
0, 23, 1, /* Curved beam */
12, 24, 1, /* Parabolic beam */
0, 31, 1, /* Straight pipe */
0, 32, 1, /* Curved pipe */
7, 41, 0, /* Plane Stress Linear Triangle */
8, 42, 0, /* Plane Stress Parabolic Triangle */
0, 43, 0, /* Plane Stress Cubic Triangle */
9, 44, 0, /* Plane Stress Linear Quadrilateral */
10, 45, 0, /* Plane Stress Parabolic Quadrilateral */
0, 46, 0, /* Plane Strain Cubic Quadrilateral */
7, 51, 0, /* Plane Strain Linear Triangle */
8, 52, 0, /* Plane Strain Parabolic Triangle */
0, 53, 0, /* Plane Strain Cubic Triangle */
9, 54, 0, /* Plane Strain Linear Quadrilateral */
10, 55, 0, /* Plane Strain Parabolic Quadrilateral */
0, 56, 0, /* Plane Strain Cubic Quadrilateral */
7, 61, 0, /* Plate Linear Triangle */
8, 62, 0, /* Plate Parabolic Triangle */
0, 63, 0, /* Plate Cubic Triangle */
9, 64, 0, /* Plate Linear Quadrilateral */
10, 65, 0, /* Plate Parabolic Quadrilateral */
0, 66, 0, /* Plate Cubic Quadrilateral */
9, 71, 0, /* Membrane Linear Quadrilateral */
8, 72, 0, /* Membrane Parabolic Triangle */
10, 73, 0, /* Membrane Cubic Triangle */
7, 74, 0, /* Membrane Linear Triangle */
0, 75, 0, /* Membrane Parabolic Quadrilateral */
0, 76, 0, /* Membrane Cubic Quadrilateral */
7, 81, 0, /* Axisymetric Solid Linear Triangle */
8, 82, 0, /* Axisymetric Solid Parabolic Triangle */
9, 84, 0, /* Axisymetric Solid Linear Quadrilateral */
10, 85, 0, /* Axisymetric Solid Parabolic Quadrilateral */
7, 91, 0, /* Thin Shell Linear Triangle */
8, 92, 0, /* Thin Shell Parabolic Triangle */
0, 93, 0, /* Thin Shell Cubic Triangle */
9, 94, 0, /* Thin Shell Linear Quadrilateral */
10, 95, 0, /* Thin Shell Parabolic Quadrilateral */
0, 96, 0, /* Thin Shell Cubic Quadrilateral */
0,101, 0, /* Thick Shell Linear Wedge */
0,102, 0, /* Thick Shell Parabolic Wedge */
0,103, 0, /* Thick Shell Cubic Wedge */
0,104, 0, /* Thick Shell Linear Brick */
0,105, 0, /* Thick Shell Parabolic Brick */
0,106, 0, /* Thick Shell Cubic Brick */
3,111, 0, /* Solid Linear Tetrahedron */
2,112, 0, /* Solid Linear Wedge */
5,113, 0, /* Solid Parabolic Wedge */
0,114, 0, /* Solid Cubic Wedge */
1,115, 0, /* Solid Linear Brick */
4,116, 0, /* Solid Parabolic Brick */
0,117, 0, /* Solid Cubic Brick */
6,118, 0, /* Solid Parabolic Tetrahedron */
0,121, 0, /* Rigid Bar */
0,122, 0, /* Rigid Element */
0,136, 0, /* Node To Node Translational Spring */
0,137, 0, /* Node To Node Rotational Spring */
0,138, 0, /* Node To Ground Translational Spring */
0,139, 0, /* Node To Ground Rotational Spring */
0,141, 0, /* Node To Node Damper */
0,142, 0, /* Node To Gound Damper */
0,151, 0, /* Node To Node Gap */
0,152, 0, /* Node To Ground Gap */
0,161, 0, /* Lumped Mass */
0,171, 0, /* Axisymetric Linear Shell */
0,172, 0, /* Axisymetric Parabolic Shell */
0,181, 0, /* Constraint */
0,191, 0, /* Plastic Cold Runner */
0,192, 0, /* Plastic Hot Runner */
0,193, 0, /* Plastic Water Line */
0,194, 0, /* Plastic Fountain */
0,195, 0, /* Plastic Baffle */
0,196, 0, /* Plastic Rod Heater */
0,201, 0, /* Linear node-to-node interface */
0,202, 0, /* Linear edge-to-edge interface */
0,203, 0, /* Parabolic edge-to-edge interface */
0,204, 0, /* Linear face-to-face interface */
0,208, 0, /* Parabolic face-to-face interface */
0,212, 0, /* Linear axisymmetric interface */
0,213, 0, /* Parabolic axisymmetric interface */
0,221, 0, /* Linear rigid surface */
0,222, 0, /* Parabolic rigin surface */
0,231, 0, /* Axisymetric linear rigid surface */
0,232, 0, /* Axisymetric parabolic rigid surface */ };
/* eltype= 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 0, 0, 0 */
int numnodes[16]= {0, 8, 6, 4,20,15,10, 3, 6, 4, 8, 2, 3, 0, 0, 0};
int smatch[2][16]= {0, 9, 7, 7,10,10, 8,11,12,11,12, 0, 0, 0, 0, 0,
0, 0, 9, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int dimensions[16]={0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 0, 0, 0};
char nomabq[16][10]= {
"null", "C3D8", "C3D6", "C3D4", "C3D20", "C3D15", "C3D10", "S3",
"S6", "S4R", "S8R", "B31", "B32", "null", "null", "null", };
int mapunv[16][21]= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null */
1, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D8 */
2, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D6 */
3, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D4 */
4, 1, 3, 5, 7,13,15,17,19, 2, 4, 6, 8,14,16,18,20, 9,10,11,12, /* C3D20*/
5, 1, 3, 5,10,12,14, 2, 4, 6,11, 13,15, 7, 8, 9, 0, 0, 0, 0, 0, /* C3D15*/
6, 1, 3, 5,10, 2, 4, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D10*/
7, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S3 */
8, 1, 5, 3, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S6 */
9, 1, 4, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S4R */
10, 1, 7, 5, 3, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S8R */
11, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B31 */
12, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B32 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null */};
/* pointers to faces tables. */
int elpointer[15]={0,2,1,3,2,1,3,5,5,4,4,0,0,0,0};
/* faces contains ABAQUS convention of node numbers at element faces. */
/* first line is empty; other 6 lines contain node numbers at max. 6 faces. */
/* faces[i][0][0] (upperleft entries): Number of faces at this element. */
/* faces[i][j][0] (left columns): Number of nodes at faces. */
int faces[6][7][5] = {
0, 0, 0, 0, 0, /* empty. */
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
5, 0, 0, 0, 0, /* wedges 6/15 nodes. */
3, 1, 2, 3, 0,
3, 4, 6, 5, 0,
4, 1, 4, 5, 2,
4, 2, 5, 6, 3,
4, 3, 6, 4, 1,
0, 0, 0, 0, 0,
6, 0, 0, 0, 0, /* Bricks 8/20 nodes. */
4, 1, 2, 3, 4,
4, 5, 8, 7, 6,
4, 1, 5, 6, 2,
4, 2, 6, 7, 3,
4, 3, 7, 8, 4,
4, 4, 8, 5, 1,
4, 0, 0, 0, 0, /* tetrahedra, 4/10 nodes. */
3, 1, 2, 3, 0,
3, 1, 4, 2, 0,
3, 2, 4, 3, 0,
3, 3, 4, 1, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
4, 0, 0, 0, 0, /* quadrilaterals, 4/8 nodes. */
2, 1, 2, 0, 0,
2, 2, 3, 0, 0,
2, 3, 4, 0, 0,
2, 4, 1, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
3, 0, 0, 0, 0, /* triangles, 3/6 nodes. */
2, 1, 2, 0, 0,
2, 2, 3, 0, 0,
2, 3, 1, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0 };
int maxdimen, mindimen; /* min and max dimensions found in model. */
#ifdef PROOL
#define BUFSIZE 512
#define TMPNAME "prool.tmp"
int max_nument;
char tmp_groupname[BUFSIZE];
int get_groupname(char *input, char *output)
// input - input line
// output - groupname
// return 0 if error, non zero if not error
{
char *cc;
output[0]=0;
strcpy(output,input);
cc=strchr(output,'\r');
if (cc) *cc=0;
cc=strchr(output,'\n');
if (cc) *cc=0;
cc=strchr(output,' ');
if (cc) *cc='_';
//printf("prool: get_groupname '%s'\n", output);
return strlen(output);
}
void process_e(char *filename)
{FILE *f1, *f2;
char buf[BUFSIZE], *pp;
char tmp_buf[BUFSIZE];
int i,len;
f1=fopen(filename,"r");
if (f1==NULL) {printf("prool_process_e: can't open input file `%s'\n",filename); return;}
f2=fopen(TMPNAME,"w");
if (f2==NULL) {printf("prool_process_e: can't open tmp file `%s'\n",TMPNAME); return;}
while(!feof(f1))
{
buf[0]=0;
fgets(buf,BUFSIZE,f1);
#define LONG_NAME "PERMANENT GROUP"
// replace LONG_NAME to "gr"
if (memcmp(buf,LONG_NAME,strlen(LONG_NAME))==0)
{
strcpy(tmp_buf,buf);
strcpy(buf,"gr");
strcat(buf,pp+strlen(LONG_NAME));
}
// replace D to E
len=strlen(buf);
for (i=0;i<len;i++)
{
if (buf[i]=='D') buf[i]='E';
}
fputs(buf,f2);
}
fclose(f1);
if (fclose(f2))
{printf("prool_process_e: can't close tmp file `%s'\n",TMPNAME); return;}
}
void help(void)
{
printf
("unical1 prool's DIRTY EXPERIMENTAL mod\n\nusage: unical1 inputfile outputfile\nor\nunical1 -f inputfile outputfile\n\nProol: http://prool.kharkov.org\n\n");
}
#endif
int name_is_elem(char * groupname) // by prool
{
char prool_buffer[BUFSIZE];
int i, ret;
char *cc, *groupname0;
groupname0=groupname;
for(i=0;i<BUFSIZE;i++) prool_buffer[i]=0;
cc=prool_buffer;
while (*groupname)
{
*cc++=toupper(*groupname++);
}
if(strstr(prool_buffer,"ELEM")==NULL) ret=0;
else ret=1;
//printf("prool debug name_is_elem() name='%s' upper='%s' ret=%i\n", groupname0, prool_buffer, ret);
return ret;
}
/*============================================================================*/
int main (int argc, char **argv) {
/* printf("argc=%d\n", argc); */
#ifdef PROOL
max_nument=0;
if(argc==3)
{
exitif(strlen(argv[1])>195, "unical: sorry input file name too long.", NULL);
strcpy(inname, argv[1]);
exitif(strlen(argv[1])>195, "unical: sorry output file name too long.", NULL);
strcpy(outname, argv[2]);
printf("unical1, Copyright(C) 2011 Bernhardi \n");
printf("some modif. by prool, 2015-2017. http://prool.kharkov.org\n");
printf("unical comes with ABSOLUTELY NO WARRANTY. This is free\n");
printf("software, and you are welcome to redistribute it under\n");
printf("certain conditions, see http://www.gnu.org/licenses/gpl.html\n\n");
full=0;
}
else
if(argc==4)
{
if (strcmp(argv[1],"-f"))
{
help();
return 1;
}
full=1;
strcpy(inname,argv[2]);
strcpy(outname,argv[3]);
}
else
{
help();
//printf("unical: usage: unical inputfile outputfile\n");
exit(2);
}
#else
if(argc==2) {
exitif(strlen(argv[1])>195, "unical: sorry file name too long.", NULL);
strcpy(problem, argv[1]);
full=0; }
else if(argc==3) {
exitif(strncmp(argv[1],"-f",2)!=0, "unical: command not understood.", NULL);
exitif(strlen(argv[2])>195, "unical: sorry file name too long.", NULL);
strcpy(problem, argv[2]);
full=1; }
else {
printf("unical: usage: unical [-f] unv_filename (without extension .unv)\n");
exit(0); }
printf("unical1, Copyright(C) 2011 Bernhardi \n");
printf("unical comes with ABSOLUTELY NO WARRANTY. This is free\n");
printf("software, and you are welcome to redistribute it under\n");
printf("certain conditions, see http://www.gnu.org/licenses/gpl.html\n\n");
strcpy(inname, problem);
strcat(inname, ".unv");
#endif
#ifdef PROOL
process_e(inname); // convert exponent letter D+00 to E+00
strcpy(inname,TMPNAME);
#endif
//printf("unical: Reading from file %s\n",inname);
fid = fopen(inname,"r");
exitif(fid==0,"Error reading from file ",inname);
countuni(); /* determine number of elements, nodes, etc. */
printf("unical: maxnode=%d, sumele=%d\n", maxnode, sumele);
allocate(); /* allocate large arrays. */
rewind(fid);
readnodes(); /* read nodes: coordinates. */
rewind(fid);
readelements(); /* read element connectivities. */
rewind(fid);
readgroups(); /* read group information. */
/* close universal file */
//printf("unical: closing universal file %s\n", inname);
ret = fclose(fid);
exitif(ret < 0,"while attempting to close file ",inname);
#ifndef PROOL
strcpy(outname, problem);
strcat(outname, ".inp");
#endif
printf("unical: writing to file %s\n",outname);
fid = fopen(outname,"w");
exitif(fid==0,"Error opening file ",outname);
writemesh(); /* write node point and element data to abaqus/calculix input file. */
surface(); /* process groups for boundary conditions. */
#ifndef PROOL
/* write standard ABAQUS procedure calls: *frequency step. */
fprintf(fid,"*material, name=steel\n");
fprintf(fid,"*elastic\n");
fprintf(fid,"209000.0, 0.3\n");
fprintf(fid,"*density\n");
fprintf(fid,"7.85e-09\n");
fprintf(fid,"*step\n");
fprintf(fid,"*frequency\n");
fprintf(fid,"12\n");
fprintf(fid,"*nodefile\n");
fprintf(fid,"u\n");
fprintf(fid,"*elfile, output=3D\n");
fprintf(fid,"s, e\n");
fprintf(fid,"*endstep\n");
#endif
/* close abaqus/calculix input file */
//printf("unical: closing file %s\n", outname);
fprintf(fid,"\n"); // prool: end of file
ret = fclose(fid);
exitif(ret < 0,"while attempting to close file ",outname);
printf("unical: conversion is done. check results carefully! \n");
printf("unical: returning to system. \n");
#ifdef PROOL
if (remove(TMPNAME)) {printf("can't delete tmp file `%s'\n",TMPNAME); exit(1);}
#endif
exit(0); }
/*===========================================================================*/
void countuni() {
int i;
int ncard;
int prool_i, prool_counter;
/* Start counting elements and nodes on data set. */
for(i=1;i<=15;i++) maxele[i]=0;
sumele=0;
maxnode=0;
maxgroup=0;
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("countunv: end-of-file while reading from %s\n", inname);
break; }
//printf("countunv: line=%s\n", line);
if(strncmp(line, " -1",6)==0) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("countunv: end-of-file while reading from %s\n", inname);
break; }
ret=sscanf(line, "%d", &key);
exitif(ret==0, "countunv: unexpected error 1 while reading from ", inname);
//printf("countunv: inname=%s, key=%d\n", inname, key);
if(key==2411) {
printf("countunv: processing dataset 2411, nodes.\n");
for(;;) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading Set 2411 from ",
inname);
ret=sscanf(line, "%d", &key);
exitif(ret==0, "countunv: unexpected error 1 while reading Set 2411 from ",
inname);
//printf("countunv: node point number =%d\n", key);
if(key==-1) break;
maxnode++;
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading Set 2411 from ",
inname); } }
else if(key==2412) {
printf("countunv: processing dataset 2412, elements.\n");
for(;;) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2412 from ",
inname);
//printf("countunv: line=%s\n", line);
ret=sscanf(line, "%d %d ", &key,&utype);
exitif(ret==0, "countunv: unexpected error 1 while reading set 2412 from ",
inname);
if(key==-1) break;
//printf("countunv: key=%d, utype=%d\n", key, utype);
exitif(utype<1||utype>232, "countunv: wrong type of element.", 0);
for(i=1;i<=86;i++) {
if(utype==eltypes[i][1]) {
eltype=eltypes[i][0];
btype=eltypes[i][2];
break; } }
//printf("countunv: key=%d, utype=%d, eltype=%d\n", key,utype,eltype);
sumele++;
maxele[eltype]++;
//printf("maxele[%d]=%d\n",eltype,maxele[eltype]);
if(btype==1) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2412 from ",
inname); }
ncard=numnodes[eltype]/8;
if(numnodes[eltype]%8>0) ncard=ncard+1;
for(j=0;j<ncard;j++) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2412 from ",
inname); } } }
else if((key==2467)||(key==2477)){ // process block 2467 or 2477. prool
printf("countunv: processing dataset 2467, groups.\n");
for(;;) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: error #1: unexpected end-of-line while reading set 2467 from ", inname);
ret=sscanf(line, "%d %d %d %d %d %d %d %d %d", &groupnumber,&dummy, &dummy,&dummy,&dummy, &dummy,&dummy,&nument);
exitif(ret==0, "countunv: unexpected error 1 while reading set 2467 from ", inname);
printf("countunv: groupnumber=%d, nument=%d\n", groupnumber, nument);
if(groupnumber==-1) break;
maxgroup++;
exitif(nument<=0, "countunv: error #1 wrong nument <0", NULL);
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: error #2: unexpected end-of-line while reading set 2467 from ", inname);
ret=get_groupname(line,groupname);
exitif(ret==0, "countunv: error reading groupname.", NULL);
printf("countunv: groupname=%s\n", groupname);
#if 0 // 1 - original, 0 - prool's mod for short lines (with 1 entity)
for(i=1;i<=nument/2+nument%2;i++) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: error #3: unexpected end-of-line while reading set 2467 from ", inname); } } }
#else
prool_counter=0;
for(;;) {// begin for
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2477 from ", inname);
//printf("prool group line=%s\n", line);
prool_i=sscanf(line, "%d %d %d %d %d %d %d %d", &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
//printf("prool debug sscanf ret=%i\n", prool_i);
if (prool_i==4)
{// prool: short line
prool_counter++;
}
else
prool_counter+=2;
if (prool_counter==nument) break;
}/*end for*/
} } // prool: end of first processing
#endif
else if(key==9999) { // prool: this code is disable!
printf("prool debug countunv: processing dataset 2477, groups.\n");
for(;;) {
sret=fgets(line, maxline, fid);
//printf("prool header of group=%s\n", line);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2477 from ", inname);
ret=sscanf(line, "%d %d %d %d %d %d %d %d %d", &groupnumber,&dummy, &dummy,&dummy,&dummy, &dummy,&dummy,&nument);
exitif(ret==0, "countunv: unexpected error 1 while reading set 2477 from ", inname);
printf("prool debug countunv: groupnumber=%d, nument=%d\n", groupnumber, nument);
if(groupnumber==-1) break;
maxgroup++;
exitif(nument<=0, "countunv: error #2 wrong nument <=0", NULL);
/* calculate maximum. prool */
if (nument>max_nument) max_nument=nument;
sret=fgets(line, maxline, fid);
//printf("prool groupname=%s\n", line);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2477 from ", inname);
ret=get_groupname(line,groupname);
exitif(ret==0, "countunv: error reading groupname.", NULL);
printf("prool debug countunv: groupname=%s\n", groupname);
// by prool:
prool_counter=0;
for(;;) {// begin for
sret=fgets(line, maxline, fid);
exitif(sret==0, "countunv: unexpected end-of-line while reading set 2477 from ", inname);
//printf("prool group line=%s\n", line);
prool_i=sscanf(line, "%d %d %d %d %d %d %d %d", &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
//printf("prool debug sscanf ret=%i\n", prool_i);
if (prool_i==4)
{// prool: short line
prool_counter++;
}
else
prool_counter+=2;
if (prool_counter==nument) break;
}/*end for*/
} } // prool: end of 2477 first processing
else {
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("countunv: end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) break; } }
} }
printf("countunv: %d nodes found on dataset. \n", maxnode);
mindimen=10;
maxdimen=0;
for(i=1;i<=15;i++) {
if(maxele[i]>0) {
if(mindimen>dimensions[i])mindimen=dimensions[i];
if(maxdimen<dimensions[i])maxdimen=dimensions[i];
printf("countunv: %d elements of type %d: %s. \n", maxele[i],i,nomabq[i]);
} }
printf("countunv: %d groups found on .unv dataset. \n",maxgroup);
exitif(maxnode<=0, "countunv: no nodes found. Cannot proceed. ", 0);
exitif(sumele<=0, "countunv: no elements found. Cannot proceed. ", 0);
printf("countunv: mindimen=%d, maxdimen=%d\n", mindimen, maxdimen);
numvol=0;
for(i=0;i<=15;i++) if(dimensions[i]==maxdimen) numvol+=maxele[i];
printf("countunv: %d elements of max dimension found.\n", numvol);
}
/*===========================================================================*/
void allocate() {
int i;
/* allocate memory: Mesh. */
printf("allocate: allocating large data arrays. \n");
nodenumbers=(int*)malloc(sizeof(int)*maxnode);
exitif(nodenumbers==0,"allocate: allocation failure: node numbers.",NULL);
coords=(double*)malloc(sizeof(double)*3*maxnode);
exitif(coords==0,"allocate: allocation failure: node coordinates.",NULL);
groupnumbers=(int*)malloc(sizeof(int)*maxgroup);
exitif(groupnumbers==0,"allocate: allocation failure: group numbers.",NULL);
groupents=(int*)malloc(sizeof(int)*maxgroup);
exitif(groupents==0,"allocate: allocation failure: group lengths.",NULL);
groupnames=(char**)malloc(sizeof(char*)*maxgroup);
exitif(groupnames==0,"allocate: allocation failure: group names.",NULL);
groupmembers=(int**)malloc(sizeof(int*)*maxgroup);
exitif(groupmembers==0,"allocate: allocation failure: group members.",NULL);
grouptypes=(int**)malloc(sizeof(int*)*maxgroup);
exitif(grouptypes==0,"allocate: allocation failure: group types.",NULL);
grouppointers=(int**)malloc(sizeof(int*)*maxgroup);
exitif(grouppointers==0,"allocate: allocation failure: group pointers.",NULL);
groupeltypes=(int**)malloc(sizeof(int*)*maxgroup);
exitif(groupeltypes==0,"allocate: allocation failure: group eltypes.",NULL);
for(i=1;i<=12;i++) {
elem[i]=0;
if(maxele[i]>=0) {
elem[i]=(int*)malloc(sizeof(int)*numnodes[i]*(maxele[i]));
exitif(elem[i]==0,"allocate: allocation failure: elements.",NULL);
elnumbers[i]=(int*)malloc(sizeof(int)*(maxele[i]));
exitif(elnumbers[i]==0,"alloc failure: element numbers.",NULL); } }
surfnum=(int*)malloc(sizeof(int)*6*numvol);
exitif(surfnum==0,"allocate: allocation failure: surface element numbers.",NULL);
volelnum=(int*)malloc(sizeof(int)*6*numvol);
exitif(volelnum==0,"allocate: allocation failure: volume element numbers.",NULL);
facenum=(int*)malloc(sizeof(int)*6*numvol);
exitif(facenum==0,"allocate: allocation failure: face numbers.",NULL);
group=(int*)malloc(sizeof(int)*6*numvol);
exitif(group==0,"allocate: allocation failure: group numbers .",NULL);
}
/*===========================================================================*/
void readnodes() {
int i;
numnode=0;
/* start reading nodes. */
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readnodes: end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readnodes: end-of-file while reading from %s\n", inname);
break; }
ret=sscanf(line, "%d", &key);
exitif(ret==0, "readnodes: unexpected error 1 while reading from ", inname);
//printf("readnodes: inname=%s, key=%d\n", inname, key);
if(key==2411) {
for(;;) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readnodes: unexpected end-of-line reading Set 2411 from ",
inname);
ret=sscanf(line, "%d", &key);
exitif(ret==0, "readnodes: unexpected error 1 while reading Set 2411 from ",
inname);
//printf("readnodes: node point number =%d\n", key);
if(key==-1) break;
numnode++;
exitif(numnode>maxnode,"error too many nodes found.\n", NULL);
nodenumbers[numnode-1]=key;
sret=fgets(line, maxline, fid);
exitif(sret==0, "readnodes: unexpected end-of-line while reading Set 2411 from ",
inname);
ret=sscanf(line, "%lf %lf %lf", &x,&y,&z);
exitif(ret==0, "readnodes: unexpected error 1 while reading Set 2411 from ",
inname);
//printf("node=%d, x=%g, y=%g, z=%g\n", key,x,y,z);
coords[(numnode-1)*3]=x;
coords[(numnode-1)*3+1]=y;
coords[(numnode-1)*3+2]=z; } }
else {
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readnodes: end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) break; } } } } }
/*===========================================================================*/
void readelements() {
int i,j,k;
int ncard, *ln;
numele=0;
for(i=1;i<=12;i++) elnumber[i]=0;
/* start reading elements. */
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readelements: #1 end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readnodes: end-of-file while reading from %s\n", inname);
break; }
ret=sscanf(line, "%d", &key);
exitif(ret==0, "readelements: unexpected error 1 while reading from ", inname);
//printf("readelements: inname=%s, key=%d\n", inname, key);
if(key==2412) {
for(;;) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readelements: unexpected end-of-line, reading set 2412 from ",
inname);
ret=sscanf(line, "%d %d ", &key,&utype);
exitif(ret==0, "readelements: unexpected error 1 while reading set 2412 from ",
inname);
if(key==-1) break;
//printf("readelements: key=%d, universal element type=%d\n", key, utype);
exitif(utype<1||utype>232, "readelements: wrong type of element.", 0);
for(i=1;i<=86;i++) {
if(utype==eltypes[i][1]) {
eltype=eltypes[i][0];
btype=eltypes[i][2];
break; } }
//printf("readelements: key=%d, utype=%d, eltype=%d\n", key,utype,eltype);
//printf("readelements: numnodes[eltype]=%d\n", numnodes[eltype]);
numele++;
elnumber[eltype]++;
exitif(elnumber[eltype]>maxele[eltype],
"Sorry error too many elements.", NULL);
elnumbers[eltype][elnumber[eltype]-1]=key;
if(btype==1) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readelements: unexpected end-of-line, reading set 2412 from ",
inname); }
ncard=numnodes[eltype]/8;
if(numnodes[eltype]%8>0) ncard=ncard+1;
//printf("readelements: eltype=%d, ncard=%d\n", eltype, ncard);
for(j=0;j<ncard;j++) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readelements: unexpected end-of-line, reading set 2412 from ",
inname);
ln=elnode+j*8;
ret=sscanf(line, " %d %d %d %d %d %d %d %d ",
ln,ln+1,ln+2,ln+3,ln+4,ln+5,ln+6,ln+7);
exitif(ret<=0, "readelements: unexpected error 1 while reading elnode from ",
inname);
//printf("readelements: element=%d, nodes=%d %d %d %d %d %d %d %d\n", elnumbers[eltype][elnumber[eltype]-1], *ln,*(ln+1),*(ln+2),*(ln+3),*(ln+4),*(ln+5),*(ln+6),*(ln+7));
}
for(i=1;i<=numnodes[eltype];i++) {
k=mapunv[eltype][i];
elem[eltype][numnodes[eltype]*(elnumber[eltype]-1)+i-1]=elnode[k-1];
} } }
else {
for(;;) {
sret=fgets(line, maxline, fid);
if(sret==0) {
//printf("readelements: #2 end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) break; } } } }
//printf("prool trace #01\n");
}
/*===========================================================================*/
void readgroups() {
int i,l;
int prool_counter;
//printf("prool trace #02\n");
numgroup=-1;
/* start reading groups. */
for(;;) {
//printf("prool trace #03\n");
sret=fgets(line, maxline, fid);
//printf("prool trace #04\n");
if(sret==0) {
//printf("readgroups: end-of-file while reading from %s\n", inname);
break; }
if(strncmp(line, " -1",6)==0) {
sret=fgets(line, maxline, fid);
//printf("prool trace #05\n");
if(sret==0) {
//printf("readgroups: end-of-file while reading from %s\n", inname);
break; }
ret=sscanf(line, "%d", &key);
//printf("prool trace #06\n");
exitif(ret==0, "readnodes: unexpected error 1 while reading from ", inname);
//printf("readgroups: inname=%s, key=%d\n", inname, key);
//printf("prool trace #07\n");
if((key==2467)||(key==2477)) { // process block 2467 or 2477. prool
for(;;) {
sret=fgets(line, maxline, fid);
//printf("prool trace #08\n");
exitif(sret==0, "readgroups: unexpected end-of-line while reading set 2467 from ", inname);
ret=sscanf(line, "%d %d %d %d %d %d %d %d", &groupnumber,&dummy, &dummy,&dummy,&dummy, &dummy,&dummy,&nument);
exitif(ret==0, "readgroups: unexpected error 1 while reading set 2467 from ", inname);
printf("readgroups: groupnumber=%d, nument=%d\n", groupnumber, nument);
if(groupnumber==-1) break;
numgroup++;
exitif(numgroup>maxgroup, "readgroups: error too many groups.",NULL);
exitif(nument<=0, "readgroups: error #3 wrong nument <0", NULL);
groupnumbers[numgroup]=groupnumber;
groupents[numgroup]=nument;
/* allocate space for groups. */
groupnames[numgroup]=(char*)malloc(80*sizeof(int));
exitif(groupnames[numgroup]==0, "readgroups: sorry cannot allocate storage for groupnames. ",NULL);
groupmembers[numgroup]=(int*)malloc(sizeof(int)*nument);
exitif(groupmembers[numgroup]==0, "readgroups: cannot alloc storage for groupmembers. ",NULL);
grouptypes[numgroup]=(int*)malloc(sizeof(int)*nument);
exitif(grouptypes[numgroup]==0, "readgroups: cannot alloc storage for grouptypes. ",NULL);
grouppointers[numgroup]=(int*)malloc(sizeof(int)*nument);
exitif(grouppointers[numgroup]==0, "readgroups: cannot alloc storage for grouppointers. ",NULL);
groupeltypes[numgroup]=(int*)malloc(sizeof(int)*nument);
exitif(groupeltypes[numgroup]==0, "readgroups: cannot alloc storage for groupeltypes. ",NULL);
/* read group data. */
sret=fgets(line, maxline, fid);
exitif(sret==0, "readgroups: unexpected end-of-line while reading set 2467 from ", inname);
ret=get_groupname(line,groupname);
exitif(ret==0, "readgroups: error reading groupname.", NULL);
strcpy(groupnames[numgroup],groupname);
printf("readgroups: groupname=%s\n", groupnames[numgroup]);
#if 0 // 0 - prool's mod., 1 - original
for(i=0;i<nument/2;i++) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readgroups: unexpected end-of-line while reading set 2467 from ", inname);
ret=sscanf(line, "%d %d %d %d %d %d %d %d", elnode,elnode+1,elnode+2,elnode+3, elnode+4,elnode+5,elnode+6,elnode+7);
exitif(*(elnode)<=0||*(elnode+1)<=0||*(elnode+4)<=0||*(elnode+5)<=0, "readgroups: error wrong group ID numbers.", NULL);
grouptypes[numgroup][2*i]=*elnode;
groupmembers[numgroup][2*i]=*(elnode+1);
grouptypes[numgroup][2*i+1]=*(elnode+4);
groupmembers[numgroup][2*i+1]=*(elnode+5); }
if(nument%2==1) {
sret=fgets(line, maxline, fid);
exitif(sret==0, "readgroups: unexpected end-of-line while reading set 2467 from ", inname);
ret=sscanf(line, "%d %d %d %d %d %d %d %d", elnode,elnode+1,elnode+2,elnode+3, elnode+4,elnode+5,elnode+6,elnode+7);
exitif(*(elnode)<=0||*(elnode+1)<=0, "readgroups: error wrong group ID numbers.", NULL);
grouptypes[numgroup][nument-1]=*elnode;
groupmembers[numgroup][nument-1]=*(elnode+1); }
#else
prool_counter=0;
i=0;