42 #define getline fgets(line,MAXLINESIZE,in)
45 static int Getrow(
char *line1,FILE *io,
int upper)
55 charend = fgets(line0,MAXLINESIZE,io);
56 isend = (charend == NULL);
60 if(line0[0] ==
'#' || line0[0] ==
'!')
goto newline;
61 if(strstr(line0,
"#"))
goto newline;
65 line1[i] = toupper(line0[i]);
88 charend = fgets(line0,MAXLINESIZE,io);
89 isend = (charend == NULL);
93 if(line0[0] ==
'#' || line0[0] ==
'!')
goto newline;
94 if(strstr(line0,
"#"))
goto newline;
99 if( line0[i] ==
'd' || line0[i] ==
'D' ) {
118 charend = fgets(line0,MAXLINESIZE,io);
119 isend = (charend == NULL);
131 int boundarynodes,
int *nodeindx,
int *boundindx,
int info)
133 int i,j,
k,sideelemtype,elemind,*indx;
134 int boundarytype,minboundary,maxboundary,minnode,maxnode,sideelem,elemtype;
135 int sideind[
MAXNODESD1],elemsides,side,sidenodes,hit,nohits;
141 maxboundary = minboundary = boundindx[1];
142 minnode = maxnode = nodeindx[1];
144 for(i=1;i<=boundarynodes;i++) {
145 if(maxboundary < boundindx[i]) maxboundary = boundindx[i];
146 if(minboundary > boundindx[i]) minboundary = boundindx[i];
147 if(maxnode < nodeindx[i]) maxnode = nodeindx[i];
148 if(minnode > nodeindx[i]) minnode = nodeindx[i];
152 printf(
"Boundary types are in interval [%d, %d]\n",minboundary,maxboundary);
153 printf(
"Boundary nodes are in interval [%d, %d]\n",minnode,maxnode);
158 for(i=1;i<=data->
noknots;i++) elemhits[i] = 0;
160 for(elemind=1;elemind<=data->
noelements;elemind++) {
162 elemsides = elemtype % 100;
164 for(i=0;i<elemsides;i++) {
165 elemhits[data->
topology[elemind][i]] += 1;
170 for(boundarytype=minboundary;boundarytype <= maxboundary;boundarytype++) {
171 int boundfirst,bchits,bcsame,sideelemtype2;
179 for(i=1;i<=boundarynodes;i++) {
180 if(boundindx[i] == boundarytype)
181 indx[nodeindx[i]] =
TRUE;
185 for(elemind=1;elemind<=data->
noelements;elemind++) {
187 elemsides = elemtype / 100;
188 if(elemsides == 8) elemsides = 6;
189 else if(elemsides == 5) elemsides = 4;
190 else if(elemsides == 6) elemsides = 5;
192 if(0)
printf(
"ind=%d type=%d sides=%d\n",elemind,elemtype,elemsides);
195 for(side=0;side<elemsides;side++) {
197 sidenodes = sideelemtype%100;
199 if(0)
printf(
"sidenodes=%d side=%d\n",sidenodes,side);
203 for(i=0;i<sidenodes;i++) {
204 if(sideind[i] <= 0) {
205 if(0)
printf(
"sideind[%d] = %d\n",i,sideind[i]);
208 else if(sideind[i] > data->
noknots) {
209 if(0)
printf(
"sideind[%d] = %d (noknots=%d)\n",i,sideind[i],data->
noknots);
212 else if(!indx[sideind[i]]) {
227 for(i=0;i<sidenodes;i++)
228 if(elemhits[sideind[i]] < 2) bchits =
FALSE;
230 if(bchits && boundfirst) {
231 for(j=boundfirst;j<=sideelem;j++) {
232 if(bound->
parent2[j])
continue;
234 if(sideelemtype != sideelemtype2)
continue;
236 for(i=0;i<sidenodes;i++)
237 for(k=0;k<sidenodes;k++)
238 if(sideind[i] == sideind2[k]) bcsame++;
240 if(bcsame == sidenodes) {
244 bound->
parent[j] = elemind;
245 bound->
side[j] = side;
249 bound->
side2[j] = side;
257 bound->
parent[sideelem] = elemind;
258 bound->
side[sideelem] = side;
260 bound->
side2[sideelem] = 0;
261 bound->
types[sideelem] = boundarytype;
263 if(!boundfirst) boundfirst = sideelem;
275 if(info)
printf(
"Found %d side elements formed by %d points.\n",
276 sideelem,boundarynodes);
287 char *prefix,
int info)
294 int noknots,noelements,elemcode,maxnodes,
material;
295 int mode,allocated,nvalue,nvalue2,maxknot,nosides;
296 int boundarytype,boundarynodes,elsetactive;
297 int *nodeindx = NULL,*boundindx = NULL;
307 strcpy(filename,prefix);
308 if ((in = fopen(filename,
"r")) == NULL) {
310 if ((in = fopen(filename,
"r")) == NULL) {
311 printf(
"LoadAbaqusInput: opening of the ABAQUS-file '%s' wasn't succesfull !\n",
317 printf(
"Reading input from ABAQUS input file %s.\n",filename);
338 ivalues0[0] = ivalues0[1] = 0;
349 if(strstr(line,
"**")) {
350 if(info && !allocated)
printf(
"comment: %s",line);
352 else if(strrchr(line,
'*')) {
353 if(strstr(line,
"HEAD")) {
356 else if(strstr(line,
"NODE")) {
362 else if(strstr(line,
"ELEMENT")) {
363 if(!elsetactive) material++;
364 if(strstr(line,
"S3R") || strstr(line,
"STRI3"))
366 else if(strstr(line,
"2D4") || strstr(line,
"SP4") || strstr(line,
"AX4")
367 || strstr(line,
"S4") || strstr(line,
"CPE4"))
369 else if(strstr(line,
"2D8") || strstr(line,
"AX8"))
371 else if(strstr(line,
"3D4"))
373 else if(strstr(line,
"3D5"))
375 else if(strstr(line,
"3D6"))
377 else if(strstr(line,
"3D8"))
379 else if(strstr(line,
"3D20"))
382 printf(
"Unknown element code: %s\n",line);
384 if(maxnodes < elemcode%100) maxnodes = elemcode%100;
386 if(1)
printf(
"Loading elements of type %d starting from element %d.\n",
387 elemcode,noelements);
389 else if(strstr(line,
"BOUNDARY") || strstr(line,
"CLOAD")) {
393 else if(strstr(line,
"NSET")) {
397 else if(strstr(line,
"ELSET")) {
403 if(!allocated)
printf(
"unknown command: %s",line);
412 if(info)
printf(
"Loading Abacus input file:\n%s",line);
417 i = (int)(rvalues[0]+0.5);
422 data->
x[noknots] = rvalues[1];
423 data->
y[noknots] = rvalues[2];
424 data->
z[noknots] = rvalues[3];
427 if(maxknot < i) maxknot = i;
439 for(i=0;i<nvalue-1;i++)
440 data->
topology[noelements][i] = ivalues[i+1];
443 if(nvalue < elemcode % 100) {
446 if(ivalues[nvalue-1] == 0) nvalue--;
448 for(i=0;i<nvalue2;i++)
449 data->
topology[noelements][nvalue-1+i] = ivalues[i];
457 if(ivalues[0] == ivalues0[0] & ivalues[1] != ivalues0[1])
continue;
458 ivalues0[0] = ivalues[0];
459 ivalues0[1] = ivalues[1];
463 nodeindx[boundarynodes] = ivalues[0];
464 boundindx[boundarynodes] = boundarytype;
472 for(i=0;i<nvalue;i++) {
474 nodeindx[boundarynodes] = ivalues[i];
475 boundindx[boundarynodes] = boundarytype;
479 boundarynodes += nvalue;
486 for(i=0;i<nvalue;i++) {
494 printf(
"Unknown case: %d\n",mode);
502 if(allocated ==
TRUE) {
503 if(info)
printf(
"The mesh was loaded from file %s.\n",filename);
511 if(noknots != maxknot) {
512 if(info)
printf(
"There are %d nodes but maximum index is %d.\n",
514 if(info)
printf(
"Renumbering elements\n");
515 for(j=1;j<=noelements;j++)
534 if(info)
printf(
"Allocating for %d knots and %d %d-node elements.\n",
535 noknots,noelements,maxnodes);
538 nosides = 2*boundarynodes;
539 printf(
"There are %d boundary nodes, thus allocating %d elements\n",
540 boundarynodes,nosides);
542 nodeindx =
Ivector(1,boundarynodes);
543 boundindx =
Ivector(1,boundarynodes);
546 for(i=1;i<=maxknot;i++)
557 char *prefix,
int info)
561 int noknots,noelements,elemcode,maxnodes,
material;
562 int mode,allocated,maxknot,minknot;
563 int boundarytype,boundarynodes,nodes;
572 strcpy(filename,prefix);
573 if ((in = fopen(filename,
"r")) == NULL) {
575 if ((in = fopen(filename,
"r")) == NULL) {
576 printf(
"LoadNastranInput: opening of the Nastran file '%s' wasn't succesfull !\n",
582 if(info)
printf(
"Reading mesh from Nastran file %s.\n",filename);
602 ivalues0[0] = ivalues0[1] = 0;
611 if(!allocated)
printf(
"comment: %s",line);
613 else if(strstr(line,
"GRID")) {
615 if(0)
printf(
"line=%s\n",line);
626 if(j > maxknot) maxknot = j;
627 if(j < minknot) minknot = j;
639 else if(strstr(line,
"TETRA")) {
642 if(nodes > maxnodes) maxnodes = nodes;
652 else if(strstr(line,
"PYRAM")) {
655 if(nodes > maxnodes) maxnodes = nodes;
665 else if(strstr(line,
"PENTA")) {
668 if(nodes > maxnodes) maxnodes = nodes;
678 else if(strstr(line,
"CHEXA")) {
681 if(nodes > maxnodes) maxnodes = nodes;
697 else if(strstr(line,
"ENDDAT")) {
701 printf(
"unknown command: %s",line);
707 if(allocated ==
TRUE) {
708 if(info)
printf(
"The mesh was loaded from file %s.\n",filename);
719 printf(
"maxknot = %d minknot = %d\n",maxknot,minknot);
721 if(info)
printf(
"Allocating for %d knots and %d %d-node elements.\n",
722 noknots,noelements,maxnodes);
735 int order203[]={1,3,2};
736 int order306[]={1,3,5,2,4,6};
737 int order408[]={1,3,5,7,2,4,6,8};
738 int order409[]={1,3,5,7,2,4,6,8,9};
739 int order510[]={1,3,6,10,2,5,4,7,8,9};
740 int order605[]={1,2,4,3,5};
741 int order808[]={1,2,4,3,5,6,8,7};
742 int order827[]={1,3,9,7,19,21,27,25,2,6,8,4,10,12,18,16,20,24,26,22,11,15,17,13,5,23,14};
745 if(typeflag > 10) dim -= 1;
754 oldtopology[i] = topology[i];
756 topology[i] = oldtopology[order203[i]-1];
763 oldtopology[i] = topology[i];
765 topology[i] = oldtopology[order306[i]-1];
767 else if(nodes == 8) {
770 oldtopology[i] = topology[i];
772 topology[i] = oldtopology[order408[i]-1];
774 else if(nodes == 9) {
777 oldtopology[i] = topology[i];
779 topology[i] = oldtopology[order409[i]-1];
786 else if(nodes == 10) {
789 oldtopology[i] = topology[i];
791 topology[i] = oldtopology[order510[i]-1];
793 else if(nodes == 5) {
796 oldtopology[i] = topology[i];
798 topology[i] = oldtopology[order605[i]-1];
800 else if(nodes == 6) {
803 else if(nodes == 8) {
805 oldtopology[i] = topology[i];
807 topology[i] = oldtopology[order808[i]-1];
810 else if(nodes == 27) {
812 oldtopology[i] = topology[i];
814 topology[i] = oldtopology[order827[i]-1];
818 printf(
"Unknown Fidap elementtype with %d nodes.\n",nodes);
822 else printf(
"ReorderFidapNodes: unknown dimension (%d)\n",data->
dim);
823 if(0)
printf(
"dim = %d element = %d elemtype = %d\n",dim,element,data->
elementtypes[element]);
836 int noknots,noelements,
dim,novel,elemcode,maxnodes;
837 int mode,maxknot,totelems,entity,maxentity;
840 int i,j,
k,*ind,geoflag,typeflag;
849 if ((in = fopen(filename,
"r")) == NULL) {
851 if ((in = fopen(filename,
"r")) == NULL) {
852 printf(
"LoadFidapInput: opening of the Fidap-file '%s' wasn't succesfull !\n",
875 if(line==
"")
goto end;
876 if(strstr(line,
"END"))
goto end;
879 if(strstr(line,
"FIDAP NEUTRAL FILE")) mode = 1;
880 else if(strstr(line,
"NO. OF NODES")) mode = 2;
881 else if(strstr(line,
"TEMPERATURE/SPECIES FLAGS")) mode = 3;
882 else if(strstr(line,
"PRESSURE FLAGS")) mode = 4;
883 else if(strstr(line,
"NODAL COORDINATES")) mode = 5;
884 else if(strstr(line,
"BOUNDARY CONDITIONS")) mode = 6;
885 else if(strstr(line,
"ELEMENT GROUPS")) mode = 7;
886 else if(strstr(line,
"GROUP:")) mode = 8;
887 else if(strstr(line,
"VELOCITY")) mode = 10;
888 else if(strstr(line,
"TEMPERATURE")) mode = 11;
889 else if(0)
printf(
"unknown: %s",line);
894 if(info)
printf(
"Loading FIDAP input file %s\n",filename);
896 if(info)
printf(
"Name of the case: %s",line);
902 if(0)
printf(
"Reading the header info\n");
903 sscanf(line,
"%d%d%d%d%d",&noknots,&noelements,
904 &nogroups,&dim,&novel);
914 if(info)
printf(
"Allocating for %d knots and %d %d-node elements.\n",
915 noknots,noelements,maxnodes);
917 if(info)
printf(
"Reading the nodes\n");
918 for(i=1;i<=noknots;i++) {
921 sscanf(line,
"%d%le%le",&knotno,
922 &(data->
x[i]),&(data->
y[i]));
924 sscanf(line,
"%d%le%le%le",&knotno,
925 &(data->
x[i]),&(data->
y[i]),&(data->
z[i]));
931 int val,group,elems,nodes;
937 sscanf(&line[i],
"%d",&group);
941 sscanf(&line[i],
"%d",&elems);
945 sscanf(&line[i],
"%d",&nodes);
949 sscanf(&line[i],
"%d",&geoflag);
953 sscanf(&line[i],
"%d",&typeflag);
959 sscanf(&line[i],
"%s",entityname);
961 if(nodes > maxnodes) {
962 if(info)
printf(
"Allocating a %d-node topology matrix\n",nodes);
963 topology =
Imatrix(1,noelements,0,nodes-1);
965 for(j=1;j<=totelems;j++)
967 topology[j][i] = data->
topology[j][i];
974 if(0)
printf(
"Reading %d element topologies with %d nodes for %s\n",
975 elems,nodes,entityname);
977 for(entity=1;entity<=maxentity;entity++) {
978 k = strcmp(entityname,data->
bodyname[entity]);
982 if(entity > maxentity) {
984 strcpy(data->
bodyname[entity],entityname);
985 if(info)
printf(
"Found new entity: %s\n",entityname);
988 for(i=totelems+1;i<=totelems+elems;i++) {
999 printf(
"Elementtype is zero!\n");
1002 if(entity) data->
material[i] = entity;
1012 if(info)
printf(
"Reading the velocity field\n");
1014 vel = data->
dofs[2];
1015 for(j=1;j<=noknots;j++) {
1018 sscanf(line,
"%le%le",&(vel[2*j-1]),&(vel[2*j]));
1020 sscanf(line,
"%le%le%le",&(vel[3*j-2]),&(vel[3*j-1]),&(vel[3*j]));
1026 if(info)
printf(
"Reading the temperature field\n");
1028 temp = data->
dofs[1];
1029 for(j=1;j<=noknots;j++) {
1031 sscanf(line,
"%le",&(temp[j]));
1045 for(i=1;i<=noelements;i++)
1049 if(maxknot > noknots) {
1050 if(info)
printf(
"Renumbering the nodes from 1 to %d\n",noknots);
1053 for(i=1;i<=maxknot;i++)
1056 for(i=1;i<=noelements;i++)
1060 for(j=1;j<=noknots;j++) {
1062 while(ind[i]==0) i++;
1065 for(i=1;i<=noelements;i++)
1075 if(info)
printf(
"Finished reading the Fidap neutral file\n");
1087 int element,
int dim,
int nodes)
1089 int i,*topology,elementtype = 0;
1090 int order820[]={1,2,3,4,5,6,7,8,9,10,11,12,17,18,19,20,13,14,15,16};
1091 int order504[]={1,2,3,5};
1092 int order306[]={1,2,3,5,6,8};
1093 int order510[]={1,2,3,5,9,10,12,17,18,19};
1094 int order613[]={1,2,3,4,5,9,10,11,12,17,18,19,20};
1098 if(oldtopology[2] == oldtopology[3]) elementtype = 510;
1099 else if(oldtopology[4] == oldtopology[5]) elementtype = 613;
1100 else elementtype = 820;
1103 if(oldtopology[2] == oldtopology[3]) elementtype = 504;
1104 else if(oldtopology[4] == oldtopology[5]) elementtype = 605;
1105 else elementtype = 808;
1107 if(nodes == 4) elementtype = 504;
1108 if(nodes == 10) elementtype = 510;
1111 if(nodes == 9) elementtype = 408;
1113 if(oldtopology[3] == oldtopology[6])
1118 if(nodes == 4) elementtype = 404;
1119 if(nodes == 10) elementtype = 310;
1120 if(nodes == 6) elementtype = 306;
1121 if(nodes == 3) elementtype = 303;
1124 if(nodes == 4) elementtype = 204;
1125 if(nodes == 3) elementtype = 203;
1126 if(nodes == 2) elementtype = 202;
1130 printf(
"Unknown elementtype in element %d (%d nodes, %d dim).\n",
1135 topology = data->
topology[element];
1137 switch (elementtype) {
1140 for(i=0;i<elementtype%100;i++)
1141 topology[i] = oldtopology[order820[i]-1];
1145 for(i=0;i<elementtype%100;i++)
1146 topology[i] = oldtopology[order504[i]-1];
1151 for(i=0;i<elementtype%100;i++) {
1152 if(oldtopology[2] == oldtopology[3])
1153 topology[i] = oldtopology[order510[i]-1];
1155 topology[i] = oldtopology[i];
1160 for(i=0;i<elementtype%100;i++) {
1161 topology[i] = oldtopology[i];
1166 for(i=0;i<elementtype%100;i++) {
1167 if(oldtopology[4] == oldtopology[5])
1168 topology[i] = oldtopology[order613[i]-1];
1170 topology[i] = oldtopology[i];
1175 for(i=0;i<elementtype%100;i++) {
1176 if(oldtopology[3] == oldtopology[6])
1177 topology[i] = oldtopology[order306[i]-1];
1179 topology[i] = oldtopology[i];
1184 for(i=0;i<elementtype%100;i++)
1185 topology[i] = oldtopology[i];
1192 char *prefix,
int info)
1195 int noknots = 0,noelements = 0,nosides,sidetype,currenttype;
1196 int maxindx,*indx,*revindx,topology[100],ind;
1197 int i,j,
k,l,imax,*nodeindx,*boundindx,boundarynodes;
1198 int noansystypes,*ansysdim,*ansysnodes,*ansystypes,boundarytypes = 0;
1199 int namesexist,maxside,sides;
1208 sprintf(filename,
"%s.header",prefix);
1209 if ((in = fopen(filename,
"r")) == NULL) {
1210 printf(
"LoadAnsysInput: The opening of the header-file %s failed!\n",
1215 if(info)
printf(
"Calculating Ansys elementtypes from %s\n",filename);
1219 printf(
"There seems to be %d elementytypes in file %s.\n",noansystypes,filename);
1221 ansysdim =
Ivector(1,noansystypes);
1222 ansysnodes =
Ivector(1,noansystypes);
1223 ansystypes =
Ivector(1,noansystypes);
1226 for(i=0;i<=noansystypes;i++) {
1227 Real dummy1,dummy2,dummy3;
1233 sscanf(line,
"%le %le %le",&dummy1,&dummy2,&dummy3);
1236 noelements = (int) (dummy1+0.5);
1237 noknots = (int) (dummy2+0.5);
1238 boundarytypes = (int) (dummy3+0.5);
1241 ansysdim[i] = (int) (dummy1+0.5);
1242 ansysnodes[i] = (int) (dummy2+0.5);
1243 ansystypes[i] = (int) (dummy3+0.5);
1248 printf(
"Ansys file has %d elements, %d nodes and %d boundary types.\n",
1249 noelements,noknots,boundarytypes);
1253 sprintf(filename,
"%s.names",prefix);
1254 in = fopen(filename,
"r");
1260 if(namesexist)
printf(
"Using names of bodies and boundaries\n");
1265 sprintf(filename,
"%s.node",prefix);
1266 if ((in = fopen(filename,
"r")) == NULL) {
1267 printf(
"LoadAnsysInput: The opening of the nodes-file %s failed!\n",
1272 if(info)
printf(
"Calculating Ansys nodes from %s\n",filename);
1275 if(info)
printf(
"There seems to be %d nodes in file %s.\n",i,filename);
1276 if(i != noknots)
printf(
"Conflicting number of nodes %d vs %d!\n",i,noknots);
1285 for(i=1;i<=noansystypes;i++) {
1286 if(ansysdim[i] > data->
dim) data->
dim = ansysdim[i];
1294 if(info)
printf(
"Allocating for %d nodes and %d elements with max. %d nodes in %d-dim.\n",
1299 for(i=1;i<=noknots;i++) indx[i] = 0;
1301 if(info)
printf(
"Loading %d Ansys nodes from %s\n",noknots,filename);
1303 for(i=1;i<=noknots;i++) {
1307 if(cp[0] ==
'.') cp++;
1310 if(!cp) x = y = z = 0.0;
1313 if(!cp) y = z = 0.0;
1314 else if(data->
dim == 3) {
1321 if(data->
dim == 3) data->
z[i] =
z;
1327 for(i=1;i<=noknots;i++)
1328 if(indx[i] > maxindx) maxindx = indx[i];
1331 if(maxindx > noknots) {
1332 printf(
"There are %d nodes with indexes up to %d.\n",
1334 for(i=1;i<=maxindx;i++)
1336 for(i=1;i<=noknots;i++)
1337 revindx[indx[i]] = i;
1340 for(i=1;i<=noknots;i++)
1346 sprintf(filename,
"%s.elem",prefix);
1347 if ((in = fopen(filename,
"r")) == NULL) {
1348 printf(
"LoadAnsysInput: The opening of the element-file %s failed!\n",
1353 if(info)
printf(
"Loading %d Ansys elements from %s\n",noelements,filename);
1355 for(j=1;j<=noelements;j++) {
1362 if(cp[0] ==
'.') cp++;
1363 topology[i] = revindx[ind];
1369 for(k=1;k<=noansystypes;k++)
1370 if(ansystypes[k] == currenttype)
break;
1371 if(ansystypes[k] != currenttype) k=1;
1373 if(ansysnodes[k] > 8) {
1377 if(ansysnodes[k] == 10 && topology[2] != topology[3])
1382 for(i=8;i<imax;i++) {
1384 if(cp[0] ==
'.') cp++;
1385 topology[i] = revindx[ind];
1396 sprintf(filename,
"%s.boundary",prefix);
1397 printf(
"Calculating nodes in file %s\n",filename);
1398 if ((in = fopen(filename,
"r")) == NULL) {
1399 printf(
"LoadAnsysInput: The opening of the boundary-file %s failed!\n",
1406 if(!strstr(line,
"Boundary")) j++;
1409 nosides = 2*boundarynodes;
1411 if(info)
printf(
"There are %d boundary nodes, allocating %d elements\n",
1412 boundarynodes,nosides);
1414 nodeindx =
Ivector(1,boundarynodes);
1415 boundindx =
Ivector(1,boundarynodes);
1417 if(info)
printf(
"Loading Ansys boundary from %s\n",filename);
1419 for(i=1;i<=boundarynodes;i++) nodeindx[i] = boundindx[i] = 0;
1425 if(strstr(line,
"Boundary")) {
1426 sscanf(line,
"%d",&sidetype);
1427 maxside =
MAX(sidetype,maxside);
1431 sscanf(line,
"%d",&k);
1432 nodeindx[j] = revindx[
k];
1433 if(!nodeindx[j])
printf(
"The boundary %dth node %d is not in index list\n",j,k);
1434 boundindx[j] = sidetype;
1437 printf(
"Found %d boundary nodes with %d as maximum side.\n",j,maxside);
1443 int bcind,*bctypes = NULL,*bctypeused = NULL,*bcused = NULL,newsides = 0;
1446 if(bound[0].nosides) {
1449 bctypeused =
Ivector(1,maxside);
1450 bcused =
Ivector(1,bound[0].nosides);
1453 for(i=1;i<=maxside;i++)
1454 bctypeused[i] =
FALSE;
1457 sprintf(filename,
"%s.names",prefix);
1458 in = fopen(filename,
"r");
1462 sscanf(line,
"%d%s%s%d",&bcind,&text[0],&text2[0],&sides);
1464 if(strstr(text2,
"BODY")) {
1466 sscanf(line,
"%d%d",&j,&bcind);
1467 strcpy(data->
bodyname[bcind],text);
1469 else if(strstr(text2,
"BOUNDARY")) {
1471 for(i=1;i<=maxside;i++)
1473 for(i=1;i<=sides;i++) {
1475 sscanf(line,
"%d%d",&j,&bcind);
1476 bctypes[bcind] =
TRUE;
1480 for(i=1;i<=maxside;i++)
1481 if(bctypes[i] && !bctypeused[i])
break;
1484 bctypeused[bcind] =
TRUE;
1485 if(0)
printf(
"First unused boundary is of type %d\n",bcind);
1490 for(i=1;i<=bound[0].
nosides;i++) {
1491 j = bound[0].
types[i];
1494 if(!bctypes[j])
continue;
1504 bound[1].
types[newsides] = bcind;
1506 bound[1].
side[newsides] = bound[0].
side[i];
1508 bound[1].
side2[newsides] = bound[0].
side2[i];
1512 if(info)
printf(
"There are %d boundary elements with name %s.\n",k+l,data->
boundaryname[bcind]);
1519 if(bound[0].nosides) {
1520 for(i=1;i<=bound[0].
nosides;i++)
1521 if(bcused[i]) bound[0].
types[i] = bcused[i];
1524 if(info)
printf(
"Created %d additional boundary elements to achieve unique naming.\n",newsides);
1542 int element,
int dim,
int nodes)
1544 int i,*topology,elementtype = 0;
1545 int order808[]={1,2,4,3,5,6,8,7};
1546 int order706[]={1,4,6,2,3,5};
1547 int order404[]={1,2,3,4};
1550 if(nodes == 8) elementtype = 808;
1551 if(nodes == 6) elementtype = 706;
1552 if(nodes == 4) elementtype = 504;
1555 if(nodes == 4) elementtype = 404;
1556 if(nodes == 3) elementtype = 303;
1560 printf(
"Unknown elementtype in element %d (%d nodes, %d dim).\n",
1565 topology = data->
topology[element];
1567 for(i=0;i<elementtype%100;i++) {
1568 if(elementtype == 808) topology[i] = oldtopology[order808[i]-1];
1569 else if(elementtype == 706) topology[i] = oldtopology[order706[i]-1];
1570 else if(elementtype == 404) topology[i] = oldtopology[order404[i]-1];
1571 else topology[i] = oldtopology[i];
1583 int noknots,noelements,elemcode,maxnodes;
1584 int mode,totelems,entity;
1590 int maxindx,sidenodes;
1592 int nobound,nobulk = 0,maxsidenodes,*boundtypes = NULL,**boundtopos = NULL,*boundnodes = NULL,*origtopology;
1594 if ((in = fopen(prefix,
"r")) == NULL) {
1596 if ((in = fopen(filename,
"r")) == NULL) {
1597 printf(
"LoadFieldviewInput: opening of the Fieldview-file '%s' wasn't succesfull !\n",
1629 if(line==
"")
goto end;
1630 if(strstr(line,
"END"))
goto end;
1633 if(strstr(line,
"FIELDVIEW")) mode = 1;
1634 else if(strstr(line,
"CONSTANTS")) mode = 2;
1635 else if(strstr(line,
"GRIDS")) mode = 3;
1636 else if(strstr(line,
"Boundary Table")) mode = 4;
1637 else if(strstr(line,
"Variable Names")) mode = 5;
1638 else if(strstr(line,
"Nodes")) mode = 6;
1639 else if(strstr(line,
"Boundary Faces")) mode = 7;
1640 else if(strstr(line,
"Elements")) mode = 8;
1641 else if(strstr(line,
"Variables")) mode = 9;
1642 else if(0)
printf(
"unknown: %s",line);
1648 printf(
"This is indeed a Fieldview input file.\n");
1653 if(0)
printf(
"Constants block\n");
1658 if(0)
printf(
"Grids block\n");
1663 if(0)
printf(
"Boundary Table\n");
1668 if(0)
printf(
"Variable names\n");
1675 sscanf(line,
"%d",&noknots);
1678 if(info)
printf(
"Loading %d node coordinates\n",noknots);
1684 for(i=1;i<=noknots;i++) {
1686 sscanf(line,
"%le%le%le",&x,&y,&z);
1697 sscanf(line,
"%d",&nobound);
1699 if(info)
printf(
"Loading %d boundary element definitions\n",nobound);
1701 boundtypes =
Ivector(1,nobound);
1702 boundtopos =
Imatrix(1,nobound,0,maxsidenodes-1);
1703 boundnodes =
Ivector(1,nobound);
1705 for(i=1;i<=nobound;i++) {
1711 for(j=0;j<maxsidenodes && cp;j++)
1722 if(info)
printf(
"Loading bulk element definitions\n");
1724 if(maxsidenodes == 4) noelements = noknots + nobound;
1725 else noelements = 6*noknots + nobound;
1727 origtopology =
Ivector(0,maxnodes-1);
1735 if(strstr(line,
"Variables")) mode = 9;
1736 if(mode != 8)
break;
1742 if(k == 2) maxnodes = 8;
1743 else if(k == 1) maxnodes = 4;
1747 for(j=0;j<maxnodes && cp;j++) {
1749 if(maxindx < origtopology[j]) maxindx = origtopology[j];
1754 if(nobulk+nobound == noelements+1)
1755 printf(
"Too few elements (%d) were allocated!!\n",noelements);
1760 printf(
"Found %d bulk elements\n",nobulk);
1761 if(nobulk+nobound > noelements)
printf(
"Too few elements (%d) were allocated!!\n",noelements);
1762 printf(
"Allocated %.4lg %% too many elements\n",
1763 noelements*100.0/(nobulk+nobound)-100.0);
1766 for(i=1;i<=nobound;i++) {
1768 data->
material[i+nobulk] = boundtypes[i];
1771 data->
noelements = noelements = nobulk + nobound;
1791 if(maxindx != noknots)
1792 printf(
"The maximum index %d differs from the number of nodes %d !\n",maxindx,noknots);
1803 char *prefix,
int info)
1807 int noknots,noelements,maxnodes,elematts,nodeatts,
dim;
1808 int elementtype,bcmarkers,sideelemtype;
1809 int i,j,
k,*boundnodes;
1815 if(info)
printf(
"Loading mesh in Triangle format from file %s.*\n",prefix);
1817 sprintf(nodefile,
"%s.node",prefix);
1818 if ((in = fopen(nodefile,
"r")) == NULL) {
1819 printf(
"LoadElmerInput: The opening of the nodes file %s failed!\n",nodefile);
1823 printf(
"Loading nodes from file %s\n",nodefile);
1826 sscanf(line,
"%d %d %d %d",&noknots,&dim,&nodeatts,&bcmarkers);
1830 printf(
"LoadTriangleInput assumes that the space dimension is 2, not %d.\n",dim);
1834 sprintf(elemfile,
"%s.ele",prefix);
1835 if ((in = fopen(elemfile,
"r")) == NULL) {
1836 printf(
"LoadElmerInput: The opening of the element file %s failed!\n",elemfile);
1840 printf(
"Loading elements from file %s\n",elemfile);
1843 sscanf(line,
"%d %d %d",&noelements,&maxnodes,&elematts);
1852 elementtype = 300 + maxnodes;
1854 if(info)
printf(
"Allocating for %d knots and %d elements.\n",noknots,noelements);
1857 boundnodes =
Ivector(1,noknots);
1858 for(i=1;i<=noknots;i++)
1861 in = fopen(nodefile,
"r");
1863 for(i=1; i <= noknots; i++) {
1867 if(j != i)
printf(
"LoadTriangleInput: nodes i=%d j=%d\n",i,j);
1870 for(j=0;j<nodeatts;j++) {
1878 in = fopen(elemfile,
"r");
1880 for(i=1; i <= noelements; i++) {
1885 if(j != i)
printf(
"LoadTriangleInput: elem i=%d j=%d\n",i,j);
1898 sprintf(polyfile,
"%s.poly",prefix);
1899 if ((in = fopen(polyfile,
"r")) == NULL) {
1900 printf(
"LoadElmerInput: The opening of the poly file %s failed!\n",polyfile);
1904 printf(
"Loading nodes from file %s\n",polyfile);
1907 int bcelems,markers,ind1,ind2,bctype,j2,
k2,hit = 0;
1908 int elemsides,sideind[2],side,elemind = 0;
1915 sscanf(line,
"%d %d",&bcelems,&markers);
1921 for(i=1;i<=bcelems;i++) {
1925 sscanf(line,
"%d %d %d %d",&j,&ind1,&ind2,&bctype);
1927 sscanf(line,
"%d %d %d",&j,&ind1,&ind2);
1950 for(side=0;side<elemsides;side++) {
1954 if(sideind[0] == ind1 && sideind[1] == ind2) hit =
TRUE;
1955 if(sideind[0] == ind2 && sideind[1] == ind1) hit =
TRUE;
1958 bound->
parent[i] = elemind;
1959 bound->
side[i] = side;
1961 bound->
side2[i] = 0;
1962 bound->
types[i] = bctype;
1968 printf(
"Successfully read the mesh from the Triangle input file.\n");
1977 char *prefix,
int info)
1981 int noknots = 0,noelements = 0,maxnodes,
dim = 0,elementtype;
1987 sprintf(nodefile,
"%s.mesh",prefix);
1988 if(info)
printf(
"Loading mesh in Medit format from file %s\n",prefix);
1990 if ((in = fopen(nodefile,
"r")) == NULL) {
1991 printf(
"LoadElmerInput: The opening of the mesh file %s failed!\n",nodefile);
2006 elementtype = 300 + maxnodes;
2008 if(info)
printf(
"Allocating for %d knots and %d elements.\n",noknots,noelements);
2010 in = fopen(nodefile,
"r");
2017 if(strstr(line,
"END"))
goto end;
2019 if(strstr(line,
"DIMENSION")) {
2023 printf(
"dim = %d %s",dim,line);
2025 else if(strstr(line,
"VERTICES")) {
2026 printf(
"verts: %s",line);
2032 printf(
"noknots = %d %s",noknots,line);
2034 for(i=1; i <= noknots; i++) {
2037 printf(
"i=%d line=%s",i,line);
2051 else if(strstr(line,
"TRIANGLES")) {
2056 printf(
"noelements = %d %s",noelements,line);
2059 if(maxnodes < 3) maxnodes = 3;
2061 for(i=1; i <= noelements; i++) {
2073 else printf(
"unknown command: %s",line);
2080 printf(
"ALLOCATED=%d\n",allocated);
2087 printf(
"Successfully read the mesh from the Medit input file.\n");
2096 char *prefix,
int info)
2099 int noknots,noelements,elemcode,maxnodes,
material,foundsame;
2100 int mode,allocated,maxknot,nosides,sideelemtype;
2101 int boundarytype,materialtype,boundarynodes,side,parent,elemsides;
2102 int dim = 0, elemnodes = 0, elembasis = 0, elemtype = 0, bulkdone, usedmax = 0,hits;
2103 int minbulk,maxbulk,minbound,maxbound,label,
debug;
2104 int *usedno = NULL, **usedelem = NULL;
2112 strcpy(filename,prefix);
2113 if ((in = fopen(filename,
"r")) == NULL) {
2115 if ((in = fopen(filename,
"r")) == NULL) {
2116 printf(
"LoadAbaqusInput: opening of the GID-file '%s' wasn't succesfull !\n",
2122 printf(
"Reading mesh from GID file %s.\n",filename);
2132 minbulk = minbound = 1000;
2133 maxbulk = maxbound = 0;
2153 if(strstr(line,
"MESH")) {
2154 if(debug)
printf(
"MESH\n");
2156 if(strstr(line,
"dimension 3"))
2158 else if(strstr(line,
"dimension 2"))
2160 else printf(
"Unknown dimension\n");
2162 if(strstr(line,
"ElemType Tetrahedra"))
2164 else if(strstr(line,
"ElemType Triangle"))
2166 else if(strstr(line,
"ElemType Linear"))
2168 else printf(
"Unknown elementtype: %s\n",line);
2170 if(strstr(line,
"Nnode 4"))
2172 else if(strstr(line,
"Nnode 3"))
2174 else if(strstr(line,
"Nnode 2"))
2176 else printf(
"Unknown elementnode: %s\n",line);
2178 if(elemnodes > maxnodes) maxnodes = elemnodes;
2179 elemtype = elembasis + elemnodes;
2182 if(debug)
printf(
"dim=%d elemtype=%d\n",dim,elemtype);
2184 else if(strstr(line,
"Coordinates")) {
2185 if(debug)
printf(
"Start coords\n");
2188 else if(strstr(line,
"end coordinates")) {
2189 if(debug)
printf(
"End coords\n");
2192 else if(strstr(line,
"Elements")) {
2194 if(debug)
printf(
"Start boundary elems\n");
2199 if(debug)
printf(
"Start bulk elems\n");
2203 else if(strstr(line,
"end elements")) {
2204 if(debug)
printf(
"End elems\n");
2207 if(!bulkdone && allocated) {
2223 if(usedno[i] > usedmax) usedmax = usedno[i];
2230 for(i=1;i<=usedmax;i++)
2239 usedelem[ind][
k] = j;
2246 if(debug)
printf(
"mode: %d %s\n",mode,line);
2254 if(ind > noknots) noknots = ind;
2263 if(dim == 3) data->
z[ind] =
z;
2270 if(ind > noelements) noelements = ind;
2272 for(i=0;i<elemnodes;i++) {
2284 materialtype = label-minbulk+1;
2287 materialtype = maxbulk-minbulk + 2;
2292 data->
material[ind] = materialtype;
2295 if(label > maxbulk) maxbulk = label;
2296 if(label < minbulk) minbulk = label;
2306 for(i=0;i<elemnodes;i++) {
2314 if(label > maxbound) maxbound = label;
2315 if(label < minbound) minbound = label;
2322 boundarytype = label-minbound+1;
2325 boundarytype = maxbound-minbound + 2;
2332 for(i=1;i<=usedno[inds[0]];i++) {
2333 parent = usedelem[inds[0]][i];
2337 for(side=0;side<elemsides;side++) {
2341 if(elemnodes != sideelemtype%100)
printf(
"LoadGidMesh: bug?\n");
2344 for(j=0;j<elemnodes;j++)
2345 for(k=0;k<elemnodes;k++)
2346 if(sideind[j] == inds[k]) hits++;
2348 if(hits < elemnodes)
continue;
2352 bound->
parent[nosides] = parent;
2353 bound->
side[nosides] = side;
2355 bound->
side2[nosides] = 0;
2356 bound->
types[nosides] = boundarytype;
2358 else if(foundsame == 1) {
2359 if(parent == bound->
parent[nosides])
continue;
2361 bound->
parent2[nosides] = parent;
2362 bound->
side2[nosides] = side;
2364 else if(foundsame > 1) {
2365 printf(
"Boundary %d has more than 2 parents\n",nosides);
2370 printf(
"Did not find parent for side %d\n",nosides);
2374 if(debug)
printf(
"Parent of side %d is %d\n",nosides,bound->
parent[nosides]);
2391 printf(
"Allocating for %d knots and %d %d-node elements.\n",
2392 noknots,noelements,maxnodes);
2393 printf(
"Initial material indexes are at interval %d to %d.\n",minbulk,maxbulk);
2398 printf(
"Allocating %d boundary elements\n",nosides);
2399 printf(
"Initial boundary indexes are at interval %d to %d.\n",minbound,maxbound);
2418 if(info)
printf(
"The mesh was loaded from file %s.\n",filename);
2427 int order404[]={1,2,4,3};
2428 int order808[]={1,2,4,3,5,6,8,7};
2431 switch (elementtype) {
2434 for(i=0;i<elementtype%100;i++)
2435 tmptopo[i] = topo[i];
2436 for(i=0;i<elementtype%100;i++)
2437 topo[i] = tmptopo[order404[i]-1];
2441 for(i=0;i<elementtype%100;i++)
2442 tmptopo[i] = topo[i];
2443 for(i=0;i<elementtype%100;i++)
2444 topo[i] = tmptopo[order808[i]-1];
2458 int noknots,noelements,elemcode,maxnodes,
material,allocated;
2460 int dim = 0, elemnodes = 0, elembasis = 0, elemtype;
2461 int debug,
offset,domains,mindom,minbc,elemdim = 0;
2466 strcpy(filename,prefix);
2467 if ((in = fopen(filename,
"r")) == NULL) {
2469 if ((in = fopen(filename,
"r")) == NULL) {
2470 printf(
"LoadComsolMesh: opening of the Comsol mesh file '%s' wasn't succesfull !\n",
2476 printf(
"Reading mesh from Comsol mesh file %s.\n",filename);
2501 if(strstr(line,
"# sdim")) {
2504 if(debug)
printf(
"dim=%d\n",dim);
2507 else if(strstr(line,
"# number of mesh points")) {
2510 if(debug)
printf(
"noknots=%d\n",noknots);
2513 else if(strstr(line,
"# lowest mesh point index")) {
2516 if(debug)
printf(
"offset=%d\n",offset);
2519 else if(strstr(line,
"# type name")) {
2520 if(strstr(line,
"vtx")) elembasis = 100;
2521 else if(strstr(line,
"edg")) elembasis = 200;
2522 else if(strstr(line,
"tri")) elembasis = 300;
2523 else if(strstr(line,
"quad")) elembasis = 400;
2524 else if(strstr(line,
"tet")) elembasis = 500;
2525 else if(strstr(line,
"prism")) elembasis = 700;
2526 else if(strstr(line,
"hex")) elembasis = 800;
2527 else printf(
"unknown element type = %s",line);
2530 else if(strstr(line,
"# number of nodes per element")) {
2533 if(elemnodes > maxnodes) maxnodes = elemnodes;
2534 if(debug)
printf(
"elemnodes=%d\n",elemnodes);
2537 else if(strstr(line,
"# Mesh point coordinates")) {
2538 printf(
"Loading %d coordinates\n",noknots);
2540 for(i=1;i<=noknots;i++) {
2552 else if(strstr(line,
"# number of elements")) {
2558 elemtype = elemnodes + elembasis;
2561 if(debug)
printf(
"Loading %d elements of type %d\n",k,elemtype);
2562 domains = noelements;
2567 if(dim == 3 && elembasis < 300)
continue;
2568 if(dim == 2 && elembasis < 200)
continue;
2570 noelements = noelements + 1;
2575 for(j=0;j<elemnodes;j++)
2584 else if(strstr(line,
"# number of geometric entity indices") ||
2585 strstr(line,
"# number of domains")) {
2591 if(debug)
printf(
"Loading %d domains for the elements\n",k);
2596 if(dim == 3 && elembasis < 300)
continue;
2597 if(dim == 2 && elembasis < 200)
continue;
2599 domains = domains + 1;
2605 material = material - minbc + 1;
2607 material = material - mindom + 1;
2612 if(minbc > material) minbc =
material;
2615 if(mindom > material) mindom =
material;
2622 else if(strstr(line,
"#")) {
2623 if(debug)
printf(
"Unused command: %s",line);
2632 if(noknots == 0 || noelements == 0 || maxnodes == 0) {
2633 printf(
"Invalid mesh consits of %d knots and %d %d-node elements.\n",
2634 noknots,noelements,maxnodes);
2646 printf(
"Allocating for %d knots and %d %d-node elements.\n",
2647 noknots,noelements,maxnodes);
2656 if(info)
printf(
"The Comsol mesh was loaded from file %s.\n\n",filename);
2726 printf(
"Gmsh element %d does not have an Elmer counterpart!\n",gmshtype);
2736 int reorder, *porder;
2738 int order510[]={0,1,2,3,4,5,6,7,9,8};
2739 int order613[]={0,1,2,3,4,5,8,10,6,7,9,11,12};
2740 int order715[]={0,1,2,3,4,5,6,9,7,8,10,11,12,14,13};
2741 int order820[]={0,1,2,3,4,5,6,7,8,11,12,9,10,12,14,15,16,18,19,17};
2750 porder = &order510[0];
2755 porder = &order613[0];
2760 porder = &order715[0];
2765 porder = &order820[0];
2771 nodes = elemtype % 100;
2772 for(i=0;i<nodes;i++)
2773 oldtopology[i] = topology[i];
2774 for(i=0;i<nodes;i++)
2775 topology[i] = oldtopology[porder[i]];
2783 int noknots = 0,noelements = 0,maxnodes,elematts,nodeatts,nosides,
dim;
2785 int i,j,
k,dummyint,*boundnodes,allocated,*revindx,maxindx;
2786 int elemno, gmshtype, regphys, regelem, elemnodes,maxelemtype,elemdim;
2791 if ((in = fopen(filename,
"r")) == NULL) {
2792 printf(
"LoadElmerInput: The opening of the mesh file %s failed!\n",filename);
2795 if(info)
printf(
"Loading mesh in Gmsh format 1.0 from file %s\n",filename);
2812 if(info)
printf(
"Allocating for %d knots and %d elements.\n",noknots,noelements);
2815 if(maxindx > noknots) {
2817 for(i=1;i<=maxindx;i++) revindx[i] = 0;
2819 in = fopen(filename,
"r");
2826 if(strstr(line,
"END"))
goto end;
2828 if(strstr(line,
"$NOD")) {
2834 for(i=1; i <= noknots; i++) {
2840 if(maxindx > noknots) revindx[j] = i;
2846 maxindx =
MAX(j,maxindx);
2850 if(!strstr(line,
"$ENDNOD")) {
2851 printf(
"NOD section should end to string ENDNOD\n");
2856 if(strstr(line,
"$ELM")) {
2861 for(i=1; i <= noelements; i++) {
2873 maxelemtype =
MAX(maxelemtype,elementtype);
2877 if(elemnodes != elementtype%100) {
2878 printf(
"Conflict in elementtypes %d and number of nodes %d!\n",
2879 elementtype,elemnodes);
2881 for(j=0;j<elemnodes;j++)
2886 for(j=0;j<elemnodes;j++)
2890 maxnodes =
MAX(elemnodes,maxnodes);
2895 if(!strstr(line,
"$ENDELM"))
2896 printf(
"ELM section should end to string ENDELM\n");
2911 if(maxindx > noknots) {
2912 printf(
"Renumbering the Gmsh nodes from %d to %d\n",maxindx,noknots);
2914 for(i=1; i <= noelements; i++) {
2916 elemnodes = elementtype % 100;
2918 for(j=0;j<elemnodes;j++) {
2920 if(k <= 0 || k > maxindx)
2921 printf(
"index out of bounds %d\n",k);
2922 else if(revindx[k] <= 0)
2923 printf(
"unkonwn node %d %d in element %d\n",k,revindx[k],i);
2933 printf(
"Successfully read the mesh from the Gmsh input file.\n");
2942 int noknots = 0,noelements = 0,maxnodes,elematts,nodeatts,nosides,
dim,notags;
2944 int i,j,
k,dummyint,*boundnodes,allocated,*revindx,maxindx;
2945 int elemno, gmshtype, tagphys, taggeom, tagpart, elemnodes,maxelemtype,elemdim;
2946 int usetaggeom,tagmat,verno;
2951 if ((in = fopen(filename,
"r")) == NULL) {
2952 printf(
"LoadElmerInput: The opening of the mesh file %s failed!\n",filename);
2955 if(info)
printf(
"Loading mesh in Gmsh format 2.0 from file %s\n",filename);
2969 if(strstr(line,
"$End"))
continue;
2971 if(strstr(line,
"$MeshFormat")) {
2977 printf(
"Version number is not compatible with the parser: %d\n",verno);
2981 if(!strstr(line,
"$EndMeshFormat")) {
2982 printf(
"$MeshFormat section should end to string $EndMeshFormat:\n%s\n",line);
2986 else if(strstr(line,
"$Nodes")) {
2991 for(i=1; i <= noknots; i++) {
2997 if(maxindx > noknots) revindx[j] = i;
3003 maxindx =
MAX(j,maxindx);
3007 if(!strstr(line,
"$EndNodes")) {
3008 printf(
"$Nodes section should end to string $EndNodes:\n%s\n",line);
3012 else if(strstr(line,
"$Elements")) {
3017 for(i=1; i <= noelements; i++) {
3026 elemnodes = elementtype % 100;
3031 if(notags > 0) tagphys =
next_int(&cp);
3032 if(notags > 1) taggeom =
next_int(&cp);
3033 if(notags > 2) tagpart =
next_int(&cp);
3034 for(j=4;j<=notags;j++)
3046 for(j=0;j<elemnodes;j++)
3051 for(j=0;j<elemnodes;j++)
3055 maxelemtype =
MAX(maxelemtype,elementtype);
3060 if(!strstr(line,
"$EndElements")) {
3061 printf(
"$Elements section should end to string $EndElements:\n%s\n",line);
3064 else if(strstr(line,
"$PhysicalNames")) {
3065 if(info)
printf(
"Physical names are not accounted for\n");
3072 if(!strstr(line,
"$EndPhysicalNames")) {
3073 printf(
"$PhysicalNames section should end to string $EndPhysicalNames:\n%s\n",line);
3077 if(!allocated)
printf(
"Untreated command: %s",line);
3086 maxnodes = maxelemtype % 100;
3093 if(info)
printf(
"Allocating for %d knots and %d elements.\n",noknots,noelements);
3096 if(maxindx > noknots) {
3098 for(i=1;i<=maxindx;i++) revindx[i] = 0;
3105 if(maxindx > noknots) {
3106 printf(
"Renumbering the Gmsh nodes from %d to %d\n",maxindx,noknots);
3108 for(i=1; i <= noelements; i++) {
3110 elemnodes = elementtype % 100;
3112 for(j=0;j<elemnodes;j++) {
3114 if(k <= 0 || k > maxindx)
3115 printf(
"index out of bounds %d\n",k);
3116 else if(revindx[k] <= 0)
3117 printf(
"unkonwn node %d %d in element %d\n",k,revindx[k],i);
3133 if(info)
printf(
"Successfully read the mesh from the Gmsh input file.\n");
3141 char *prefix,
int info)
3147 sprintf(filename,
"%s",prefix);
3148 if ((in = fopen(filename,
"r")) == NULL) {
3149 sprintf(filename,
"%s.msh",prefix);
3150 if ((in = fopen(filename,
"r")) == NULL) {
3151 printf(
"LoadElmerInput: The opening of the mesh file %s failed!\n",filename);
3160 printf(
"Format chosen using the first line: %s",line);
3163 if(strstr(line,
"$MeshFormat"))
3166 printf(
"*****************************************************\n");
3167 printf(
"The $MeshFormat was not given, assuming Gmsh 1 format\n");
3168 printf(
"This version of Gmsh format is no longer supported\n");
3169 printf(
"Please use Gsmh 2 version for output\n");
3170 printf(
"*****************************************************\n");
3267 printf(
"Unknown elementtype in universal mesh format: %d\n",unvtype);
3279 for(i=0;i<nonodes;i++) {
3280 if( ind[i] == 0 ) redundant =
TRUE;
3281 for(j=i+1;j<nonodes;j++)
3282 if(ind[i] == ind[j]) redundant =
TRUE;
3285 printf(
"Redundant element %d: ",nonodes);
3286 for(i=0;i<nonodes;i++)
3298 int reorder, *porder;
3300 int order510[]={1,3,5,10,2,4,6,7,8,9};
3301 int order408[]={1,3,5,7,2,4,6,8};
3302 int order820[]={1,3,5,7,13,15,17,19,2,4,6,8,9,10,11,12,14,16,18,20};
3311 porder = &order510[0];
3316 porder = &order408[0];
3321 porder = &order820[0];
3327 nodes = elemtype % 100;
3328 for(i=0;i<nodes;i++)
3329 oldtopology[i] = topology[i];
3330 for(i=0;i<nodes;i++)
3331 topology[i] = oldtopology[porder[i]-1];
3339 char *prefix,
int info)
3342 int noknots,totknots,noelements,elemcode,maxnodes;
3343 int allocated,maxknot,
dim,ind,lines;
3344 int reordernodes,reorderelements,nogroups,maxnodeind,maxelem,elid,unvtype,elmertype;
3345 int nonodes,group,grouptype,mode,nopoints,nodeind,matind,physind,colorind;
3346 int debug,mingroup,maxgroup,nogroup,noentities,dummy;
3347 int *u2eind,*u2eelem;
3355 strcpy(filename,prefix);
3356 if ((in = fopen(filename,
"r")) == NULL) {
3358 if ((in = fopen(filename,
"r")) == NULL) {
3359 printf(
"LoadUniversalMesh: opening of the universal mesh file '%s' wasn't succesfull !\n",
3365 printf(
"Reading mesh from universal mesh file %s.\n",filename);
3370 reordernodes =
FALSE;
3371 reorderelements =
FALSE;
3375 elementtypes =
Ivector(0,820);
3376 for(i=0;i<=820;i++) elementtypes[i] =
FALSE;
3388 printf(
"Second round for reading data\n");
3390 printf(
"First round for allocating data\n");
3402 if(0)
printf(
"line: %d %s\n",mode,line);
3405 if( !strncmp(line,
" -1",6)) mode = 0;
3409 if( !strncmp(line,
" -1",6)) mode = 0;
3410 else if( !strncmp(line,
" 2411",6)) mode = 2411;
3411 else if( !strncmp(line,
" 2412",6)) mode = 2412;
3412 else if( !strncmp(line,
" 2467",6)) mode = 2467;
3413 else if( !strncmp(line,
" 2435",6)) mode = 2435;
3414 else if( !strncmp(line,
" 781",6)) mode = 781;
3415 else if( !strncmp(line,
" 780",6)) mode = 780;
3416 else if( allocated && strncmp(line,
" ",6))
printf(
"Unknown mode: %s",line);
3419 if(debug && mode)
printf(
"Current mode is %d\n",mode);
3422 if( mode == 2411 || mode == 781 ) {
3423 if(debug)
printf(
"Reading nodes in mode %d\n",mode);
3426 if( !strncmp(line,
" -1",6))
goto nextline;
3437 printf(
"Reordering node %d already set (%d vs. %d)\n",
3438 nodeind,u2eind[nodeind],noknots);
3440 u2eind[nodeind] = noknots;
3449 if(nodeind != noknots) reordernodes =
TRUE;
3450 maxnodeind =
MAX(maxnodeind,nodeind);
3455 if( mode == 2412 ) {
3456 if(debug)
printf(
"Reading elements from field %d\n",mode);
3459 if( !strncmp(line,
" -1",6))
goto nextline;
3471 maxnodes =
MAX(maxnodes, nonodes);
3472 if(elid != noelements) reorderelements =
TRUE;
3473 maxelem =
MAX(maxelem, elid);
3476 if(unvtype == 11 || unvtype == 21 || unvtype == 22 )
Getrow(line,in,
FALSE);
3482 printf(
"Unknown elementtype %d %d %d %d %d %d\n",
3483 elid,unvtype,physind,matind,colorind,nonodes);
3484 printf(
"line: %s\n",line);
3488 if(elmertype == 510 )
3490 else if(elmertype == 820 )
3496 if(reorderelements) u2eelem[elid] = noelements;
3498 if(debug && !elementtypes[elmertype]) {
3499 elementtypes[elmertype] =
TRUE;
3500 printf(
"new elementtype in elmer: %d (unv: %d)\n",elmertype,unvtype);
3503 if(elmertype % 100 != nonodes) {
3504 printf(
"nonodes = %d elemtype = %d elid = %d\n",nonodes,elmertype,elid);
3505 nonodes = elmertype % 100;
3510 for(i=0;i<nonodes;i++) {
3511 if( lines > 0 && i >= 8 ) {
3525 data->
material[noelements] = physind;
3528 for(i=1;i<=lines;i++)
3536 int physind2,matind2;
3538 if(debug)
printf(
"Reading elements from field %d\n",mode);
3541 if( !strncmp(line,
" -1",6))
goto nextline;
3556 maxnodes =
MAX(maxnodes, nonodes);
3557 if(elid != noelements) reorderelements =
TRUE;
3558 maxelem =
MAX(maxelem, elid);
3561 if(unvtype == 11 || unvtype == 21)
Getrow(line,in,
FALSE);
3565 if(reorderelements) u2eelem[elid] = noelements;
3569 if(debug && !elementtypes[elmertype]) {
3570 elementtypes[elmertype] =
TRUE;
3571 printf(
"new elementtype in elmer: %d (unv: %d)\n",elmertype,unvtype);
3574 if(elmertype % 100 != nonodes) {
3575 printf(
"nonodes = %d elemtype = %d elid = %d\n",nonodes,elmertype,elid);
3576 nonodes = elmertype % 100;
3580 for(i=0;i<nonodes;i++)
3588 data->
material[noelements] = physind;
3593 if( mode == 2467 || mode == 2435) {
3594 if(debug)
printf(
"Reading groups in mode %d\n",mode);
3598 if( !strncmp(line,
" -1",6))
goto nextline;
3607 if( !strncmp(line,
" -1",6))
goto nextline;
3615 sscanf(line,
"%s",entityname);
3616 strcpy(data->
bodyname[group],entityname);
3620 if(info)
printf(
"Reading group %d with %d entities: %s\n",
3621 nogroup,noentities,entityname);
3625 for(i=0;i<noentities;i++) {
3628 if( !strncmp(line,
" -1",6))
goto nextline;
3637 if(ind == 0)
continue;
3639 if( grouptype == 8 ) {
3641 if(reorderelements) ind = u2eelem[ind];
3646 else if(grouptype == 7) {
3650 data->
material[noelements+nopoints] = group;
3652 data->
topology[noelements+nopoints][0] = ind;
3658 if(k && allocated && info)
3659 printf(
"Found new group %d with elements %d: %s\n",group,elemcode,entityname);
3669 if(info)
printf(
"Done reading\n");
3675 if(info)
printf(
"Reordering %d nodes with indexes up to %d\n",noknots,maxnodeind);
3676 u2eind =
Ivector(1,maxnodeind);
3677 for(i=1;i<=maxnodeind;i++) u2eind[i] = 0;
3679 if(reorderelements) {
3680 if(info)
printf(
"Reordering %d elements with indexes up to %d\n",noelements,maxelem);
3682 for(i=1;i<=maxelem;i++) u2eelem[i] = 0;
3685 if(noknots == 0 || noelements == 0 || maxnodes == 0) {
3686 printf(
"Invalid mesh consits of %d knots and %d %d-node elements.\n",
3687 noknots,noelements,maxnodes);
3700 printf(
"Allocating for %d knots and %d %d-node elements in %d dims.\n",
3701 noknots,noelements,maxnodes,dim);
3712 for(j=1;j<=noelements;j++)
3717 if(reorderelements) {
3722 mingroup = maxgroup = data->
material[1];
3727 if(info)
printf(
"The group interval is [%d,%d]\n",mingroup,maxgroup);
3730 if(!maxgroup)
printf(
"No material groups were successfully applied\n");
3731 printf(
"Unset elements were given material index %d\n",maxgroup+1);
3739 if(info)
printf(
"The Universal mesh was loaded from file %s.\n\n",filename);
3750 int noknots,noelements,maxnodes,
material,allocated,
dim,
debug,thismat,thisknots,thiselems;
3757 strcpy(filename,prefix);
3758 if ((in = fopen(filename,
"r")) == NULL) {
3760 if ((in = fopen(filename,
"r")) == NULL) {
3761 printf(
"LoadCGsimMesh: opening of the CGsim mesh file '%s' wasn't succesfull !\n",
3767 printf(
"Reading mesh from CGsim mesh file %s.\n",filename);
3790 cp = strstr(line,
"ZONE");
3795 cp = strstr(line,
" N=");
3799 cp = strstr(line,
",E=");
3805 printf(
"thismat = %d knots = %d elems = %d\n",thismat,thisknots,thiselems);
3808 for(i=1;i<=thisknots;i++) {
3815 data->
z[noknots+i] = 0.0;
3822 else if(savedofs == 5) {
3830 for(i=1;i<=thiselems;i++) {
3838 data->
topology[noelements+i][j] = inds[j]+noknots;
3839 if(inds[2] == inds[3])
3843 data->
material[noelements+i] = thismat;
3847 noknots += thisknots;
3848 noelements += thiselems;
3854 if(noknots == 0 || noelements == 0 || maxnodes == 0) {
3855 printf(
"Invalid mesh consits of %d knots and %d %d-node elements.\n",
3856 noknots,noelements,maxnodes);
3869 printf(
"Allocating for %d knots and %d %d-node elements.\n",
3870 noknots,noelements,maxnodes);
3877 else if(savedofs == 5) {
3890 if(info)
printf(
"The CGsim mesh was loaded from file %s.\n\n",filename);