117 strcpy(command,argv[1]);
118 for(i=0;i<
MAXLINESIZE;i++) command[i] = toupper(command[i]);
120 if(strstr(command,IOmethods[i])) {
129 strcpy(command,argv[2]);
130 for(i=0;i<
MAXLINESIZE;i++) command[i] = toupper(command[i]);
132 if(strstr(command,IOmethods[i])) {
140 strcpy(eg->
filesin[0],argv[3]);
148 for(arg=first;arg <argc; arg++) {
150 if(strcmp(argv[arg],
"-silent") == 0) {
155 if(strcmp(argv[arg],
"-in") ==0 ) {
157 printf(
"The secondary input file name is required as a parameter\n");
167 if(strcmp(argv[arg],
"-out") == 0) {
169 printf(
"The output name is required as a parameter\n");
173 strcpy(eg->
filesout[0],argv[arg+1]);
177 if(strcmp(argv[arg],
"-decimals") == 0) {
181 if(strcmp(argv[arg],
"-triangles") ==0) {
183 printf(
"The rectangles will be split to triangles.\n");
185 if(strcmp(argv[arg+1],
"-")) {
191 if(strcmp(argv[arg],
"-merge") == 0) {
193 printf(
"Give a parameter for critical distance.\n");
198 eg->
cmerge = atof(argv[arg+1]);
202 if(strcmp(argv[arg],
"-relh") == 0) {
204 printf(
"Give a relative mesh density related to the specifications\n");
208 eg->
relh = atof(argv[arg+1]);
212 if(strcmp(argv[arg],
"-order") == 0) {
213 if(arg+dim >= argc) {
214 printf(
"Give %d parameters for the order vector.\n",dim);
219 eg->
corder[0] = atof(argv[arg+1]);
220 eg->
corder[1] = atof(argv[arg+2]);
221 if(dim==3) eg->
corder[2] = atof(argv[arg+3]);
225 if(strcmp(argv[arg],
"-autoorder") == 0) {
229 if(strcmp(argv[arg],
"-halo") == 0) {
232 if(strcmp(argv[arg],
"-indirect") == 0) {
235 if(strcmp(argv[arg],
"-metisorder") == 0) {
238 if(strcmp(argv[arg],
"-centralize") == 0) {
241 if(strcmp(argv[arg],
"-scale") == 0) {
242 if(arg+dim >= argc) {
243 printf(
"Give %d parameters for the scaling.\n",dim);
248 eg->
cscale[0] = atof(argv[arg+1]);
249 eg->
cscale[1] = atof(argv[arg+2]);
250 if(dim==3) eg->
cscale[2] = atof(argv[arg+3]);
254 if(strcmp(argv[arg],
"-translate") == 0) {
255 if(arg+dim >= argc) {
256 printf(
"Give %d parameters for the translate vector.\n",dim);
263 if(dim == 3) eg->
ctranslate[2] = atof(argv[arg+3]);
267 if(strcmp(argv[arg],
"-saveinterval") == 0) {
268 if(arg+dim >= argc) {
269 printf(
"Give min, max and step for the interval.\n");
279 if(strcmp(argv[arg],
"-rotate") == 0 || strcmp(argv[arg],
"-rotate") == 0) {
280 if(arg+dim >= argc) {
281 printf(
"Give three parameters for the rotation angles.\n");
286 eg->
crotate[0] = atof(argv[arg+1]);
287 eg->
crotate[1] = atof(argv[arg+2]);
288 eg->
crotate[2] = atof(argv[arg+3]);
292 if(strcmp(argv[arg],
"-clone") == 0) {
293 if(arg+dim >= argc) {
294 printf(
"Give the number of clones in each %d directions.\n",dim);
298 eg->
clone[0] = atoi(argv[arg+1]);
299 eg->
clone[1] = atoi(argv[arg+2]);
300 if(dim == 3) eg->
clone[2] = atoi(argv[arg+3]);
303 if(strcmp(argv[arg],
"-clonesize") == 0) {
304 if(arg+dim >= argc) {
305 printf(
"Give the clone size in each %d directions.\n",dim);
311 if(dim == 3) eg->
clonesize[2] = atof(argv[arg+3]);
315 if(strcmp(argv[arg],
"-unite") == 0) {
317 printf(
"The meshes will be united.\n");
320 if(strcmp(argv[arg],
"-names") == 0) {
322 printf(
"Names will be conserved when possible\n");
325 if(strcmp(argv[arg],
"-removelowdim") == 0) {
327 printf(
"Lower dimensional boundaries will be removed\n");
330 if(strcmp(argv[arg],
"-removeunused") == 0) {
332 printf(
"Nodes that do not appear in any element will be removed\n");
335 if(strcmp(argv[arg],
"-autoclean") == 0) {
340 printf(
"Lower dimensional boundaries will be removed\n");
341 printf(
"Materials and boundaries will be renumbered\n");
342 printf(
"Nodes that do not appear in any element will be removed\n");
345 if(strcmp(argv[arg],
"-polar") == 0) {
347 printf(
"Making transformation to polar coordinates.\n");
349 printf(
"The preferred radius is required as a parameter\n");
357 if(strcmp(argv[arg],
"-cylinder") == 0) {
359 printf(
"Making transformation from cylindrical to cartesian coordinates.\n");
362 if(strcmp(argv[arg],
"-reduce") == 0) {
364 printf(
"Give two material for the interval.\n");
373 if(strcmp(argv[arg],
"-increase") == 0) {
376 if(strcmp(argv[arg],
"-bulkorder") == 0) {
379 if(strcmp(argv[arg],
"-boundorder") == 0) {
382 if(strcmp(argv[arg],
"-pelem") == 0) {
383 for(i=arg+1;i<argc && strncmp(argv[i],
"-",1); i++)
387 if(strcmp(argv[arg],
"-belem") == 0) {
388 for(i=arg+1;i<argc && strncmp(argv[i],
"-",1); i++)
392 if(strcmp(argv[arg],
"-partition") == 0) {
393 if(arg+dim >= argc) {
394 printf(
"The number of partitions in %d dims is required as parameters.\n",dim);
399 eg->
partdim[0] = atoi(argv[arg+1]);
400 eg->
partdim[1] = atoi(argv[arg+2]);
401 if(dim == 3) eg->
partdim[2] = atoi(argv[arg+3]);
409 if(argv[arg+4][0] !=
'-') eg->
partopt = atoi(argv[arg+4]);
411 printf(
"The mesh will be partitioned with simple division to %d partitions.\n",
415 if(strcmp(argv[arg],
"-partorder") == 0) {
416 if(arg+dim >= argc) {
417 printf(
"Give %d parameters for the order vector.\n",dim);
424 if(dim==3) eg->
partcorder[2] = atof(argv[arg+3]);
428 if(strcmp(argv[arg],
"-metis") == 0) {
431 printf(
"The number of partitions is required as a parameter\n");
435 eg->
metis = atoi(argv[arg+1]);
436 printf(
"The mesh will be partitioned with Metis to %d partitions.\n",eg->
metis);
439 if(argv[arg+2][0] !=
'-') eg->
partopt = atoi(argv[arg+2]);
442 printf(
"This version of ElmerGrid was compiled without Metis library!\n");
446 if(strcmp(argv[arg],
"-periodic") == 0) {
447 if(arg+dim >= argc) {
448 printf(
"Give the periodic coordinate directions (e.g. 1 1 0)\n");
454 if(dim == 3) eg->
periodicdim[2] = atoi(argv[arg+3]);
458 if(strcmp(argv[arg],
"-discont") == 0) {
460 printf(
"Give the discontinuous boundary conditions.\n");
469 if(strcmp(argv[arg],
"-connect") == 0) {
471 printf(
"Give the connected boundary conditions.\n");
480 if(strcmp(argv[arg],
"-boundbound") == 0) {
481 for(i=arg+1;i<=arg+3 && i<argc; i++) {
486 if(strcmp(argv[arg],
"-bulkbound") == 0) {
487 for(i=arg+1;i<=arg+3 && i<argc; i++) {
492 if(strcmp(argv[arg],
"-boundtype") == 0) {
493 for(i=arg+1;i<argc && strncmp(argv[i],
"-",1); i++)
497 if(strcmp(argv[arg],
"-bulktype") == 0) {
498 for(i=arg+1;i<argc && strncmp(argv[i],
"-",1); i++)
503 if(strcmp(argv[arg],
"-layer") == 0) {
505 printf(
"Give four parameters for the layer: boundary, elements, thickness, ratio.\n");
522 if(strcmp(argv[arg],
"-layermove") == 0) {
524 printf(
"Give maximum number of Jacobi filters.\n");
534 if(strcmp(argv[arg],
"-divlayer") == 0) {
536 printf(
"Give four parameters for the layer: boundary, elements, relative thickness, ratio.\n");
553 if(strcmp(argv[arg],
"-3d") == 0) {
556 if(strcmp(argv[arg],
"-2d") == 0) {
559 if(strcmp(argv[arg],
"-1d") == 0) {
563 if(strcmp(argv[arg],
"-isoparam") == 0) {
566 if(strcmp(argv[arg],
"-nobound") == 0) {
572 if(strcmp(argv[arg],
"-map") ==0) {
574 printf(
"Give the name of the mapping file\n");
578 strcpy(eg->
mapfile,argv[arg+1]);
582 if(strcmp(argv[arg],
"-bcoffset") == 0) {
585 if(strcmp(argv[arg],
"-noelements") == 0) {
588 if(strcmp(argv[arg],
"-nonodes") == 0) {
589 eg->
nodes3d = atoi(argv[arg+1]);
592 if(strcmp(argv[arg],
"-sidefind") == 0) {
594 for(i=arg+1;i<argc && strncmp(argv[i],
"-",1); i++) {
595 eg->
sidebulk[i-1-arg] = atoi(argv[i]);
599 if(strcmp(argv[arg],
"-findbound") == 0) {
601 for(i=arg+1;i+1<argc && strncmp(argv[i],
"-",1); i += 2) {
602 eg->
sidebulk[i-1-arg] = atoi(argv[i]);
603 eg->
sidebulk[i-arg] = atoi(argv[i+1]);
611 ptr1 = strchr(eg->
filesout[0],
'.');
612 if (ptr1) *ptr1 =
'\0';
613 ptr1 = strchr(eg->
mapfile,
'.');
614 if (ptr1) *ptr1 =
'\0';
622 static void Goodbye()
624 printf(
"\nThank you for using Elmergrid!\n");
625 printf(
"Send bug reports and feature wishes to peter.raback@csc.fi\n");
629 static void Instructions()
631 printf(
"****************** Elmergrid ************************\n");
632 printf(
"This program can create simple 2D structured meshes consisting of\n");
633 printf(
"linear, quadratic or cubic rectangles or triangles. The meshes may\n");
634 printf(
"also be extruded and revolved to create 3D forms. In addition many\n");
635 printf(
"mesh formats may be imported into Elmer software. Some options have\n");
636 printf(
"not been properly tested. Contact the author if you face problems.\n\n");
638 printf(
"The program has two operation modes\n");
639 printf(
"A) Command file mode which has the command file as the only argument\n");
640 printf(
" 'ElmerGrid commandfile.eg'\n\n");
642 printf(
"B) Inline mode which expects at least three input parameters\n");
643 printf(
" 'ElmerGrid 1 3 test'\n\n");
644 printf(
"The first parameter defines the input file format:\n");
645 printf(
"1) .grd : Elmergrid file format\n");
646 printf(
"2) .mesh.* : Elmer input format\n");
647 printf(
"3) .ep : Elmer output format\n");
648 printf(
"4) .ansys : Ansys input format\n");
649 printf(
"5) .inp : Abaqus input format by Ideas\n");
650 printf(
"6) .msh : Nastran format\n");
651 printf(
"7) .FDNEUT : Gambit (Fidap) neutral file\n");
652 printf(
"8) .unv : Universal mesh file format\n");
653 printf(
"9) .mphtxt : Comsol Multiphysics mesh format\n");
654 printf(
"10) .dat : Fieldview format\n");
655 printf(
"11) .node,.ele: Triangle 2D mesh format\n");
656 printf(
"12) .mesh : Medit mesh format\n");
657 printf(
"13) .msh : GID mesh format\n");
658 printf(
"14) .msh : Gmsh mesh format\n");
659 printf(
"15) .ep.i : Partitioned ElmerPost format\n");
661 printf(
"\nThe second parameter defines the output file format:\n");
662 printf(
"1) .grd : ElmerGrid file format\n");
663 printf(
"2) .mesh.* : ElmerSolver format (also partitioned .part format)\n");
664 printf(
"3) .ep : ElmerPost format\n");
666 printf(
"\nThe third parameter is the name of the input file.\n");
667 printf(
"If the file does not exist, an example with the same name is created.\n");
668 printf(
"The default output file name is the same with a different suffix.\n\n");
670 printf(
"There are several additional in-line parameters that are\n");
671 printf(
"taken into account only when applicable to the given format.\n");
673 printf(
"-out str : name of the output file\n");
674 printf(
"-in str : name of a secondary input file\n");
675 printf(
"-silent : do not echo run time information\n");
676 printf(
"-decimals : number of decimals in the saved mesh (eg. 8)\n");
677 printf(
"-triangles : rectangles will be divided to triangles\n");
678 printf(
"-relh real : give relative mesh density parameter for ElmerGrid meshing\n");
679 printf(
"-merge real : merges nodes that are close to each other\n");
680 printf(
"-order real[3] : reorder elements and nodes using c1*x+c2*y+c3*z\n");
681 printf(
"-centralize : set the center of the mesh to origin\n");
682 printf(
"-scale real[3] : scale the coordinates with vector real[3]\n");
683 printf(
"-translate real[3] : translate the nodes with vector real[3]\n");
684 printf(
"-rotate real[3] : rotate around the main axis with angles real[3]\n");
685 printf(
"-clone int[3] : make ideantilcal copies of the mesh\n");
686 printf(
"-clonesize real[3] : the size of the mesh to be cloned if larger to the original\n");
687 printf(
"-unite : the meshes will be united\n");
688 printf(
"-polar real : map 2D mesh to a cylindrical shell with given radius\n");
689 printf(
"-cylinder : map 2D/3D cylindrical mesh to a cartesian mesh\n");
690 printf(
"-reduce int[2] : reduce element order at material interval [int1 int2]\n");
691 printf(
"-increase : increase element order from linear to quadratic\n");
692 printf(
"-bcoffset int : add an offset to the boundary conditions\n");
693 printf(
"-discont int : make the boundary to have secondary nodes\n");
694 printf(
"-connect int : make the boundary to have internal connection among its elements\n");
695 printf(
"-removelowdim : remove boundaries that are two ranks lower than highest dim\n");
696 printf(
"-removeunused : remove nodes that are not used in any element\n");
697 printf(
"-bulkorder : renumber materials types from 1 so that every number is used\n");
698 printf(
"-boundorder : renumber boundary types from 1 so that every number is used\n");
699 printf(
"-autoclean : this performs the united action of the three above\n");
700 printf(
"-bulkbound int[3] : set the union of materials [int1 int2] to be boundary int3\n");
701 printf(
"-boundbound int[3] : set the union of boundaries [int1 int2] to be boundary int3\n");
702 printf(
"-bulktype int[3] : set material types in interval [int1 int2] to type int3\n");
703 printf(
"-boundtype int[3] : set sidetypes in interval [int1 int2] to type int3\n");
704 printf(
"-layer int[2] real[2]: make a boundary layer for given boundary\n");
705 printf(
"-layermove int : apply Jacobi filter int times to move the layered mesh\n");
706 printf(
"-divlayer int[2] real[2]: make a boundary layer for given boundary\n");
707 printf(
"-3d / -2d / -1d : mesh is 3, 2 or 1-dimensional (applies to examples)\n");
708 printf(
"-isoparam : ensure that higher order elements are convex\n");
709 printf(
"-nobound : disable saving of boundary elements in ElmerPost format\n");
711 printf(
"\nThe following keywords are related only to the parallel Elmer computations.\n");
712 printf(
"-partition int[4] : the mesh will be partitioned in main directions\n");
713 printf(
"-partorder real[3] : in the above method, the direction of the ordering\n");
715 printf(
"-metis int[2] : the mesh will be partitioned with Metis\n");
717 printf(
"-halo : create halo for the partitioning\n");
718 printf(
"-indirect : create indirect connections in the partitioning\n");
719 printf(
"-periodic int[3] : decleare the periodic coordinate directions for parallel meshes\n");
720 printf(
"-saveinterval int[3] : the first, last and step for fusing parallel data\n");
722 if(0)
printf(
"-names : conserve name information where applicable\n");
731 static int PartitionMesh(
int nofile)
754 OptimizePartitioning(&
data[nofile],boundaries[nofile],noopt,
info);
769 if(
data[nofile].nopartitions > 1)
770 SaveElmerInputPartitioned(&
data[nofile],boundaries[nofile],filename,
eg.
decimals,
782 if(
data[nofile].variables == 0) {
785 data[nofile].dofs[1][i] = (
Real)(i);
804 int i,j,
k,allocated,surfaces,elemdim;
813 printf(
"Data is not created!\n");
818 printf(
"Setting elements of %ddim\n",elemdim);
825 for(i=0; i < mesh->
getNodes(); i++) {
827 n->
setX(0, dat->
x[i+1]);
828 n->
setX(1, dat->
y[i+1]);
829 n->
setX(2, dat->
z[i+1]);
859 if(bound[j].created ==
FALSE)
continue;
861 for(i=1;i<=bound[j].
nosides;i++) {
862 GetElementSide(bound[j].parent[i],bound[j].side[i],bound[j].normal[i],dat,ind,&sideelemtype);
864 if(sideelemtype / 100 < 3 || sideelemtype / 100 > 4)
continue;
872 if(bound[j].parent[i]) {
880 if(bound[j].parent2[i]) {
917 else if(elemdim == 2) {
954 if(bound[j].created ==
FALSE)
continue;
956 for(i=1;i<=bound[j].
nosides;i++) {
957 GetElementSide(bound[j].parent[i],bound[j].side[i],bound[j].normal[i],dat,ind,&sideelemtype);
959 if(sideelemtype / 100 != 2)
continue;
967 if(bound[j].parent[i]) {
974 if(bound[j].parent2[i]) {
1001 printf(
"Implemented only for element dimensions 2 and 3 (not %d)\n",elemdim);
1014 if(!strstr(filename,
".")) {
1015 if(info)
printf(
"There cannot be a filetype suffix without a dot: %s\n",filename);
1019 if(strstr(filename,
".eg")) mode = 0;
1020 else if(strstr(filename,
".grd")) mode = 1;
1021 else if(strstr(filename,
".ep")) mode = 3;
1022 else if(strstr(filename,
".inp")) mode = 5;
1023 else if(strstr(filename,
".nas")) mode = 6;
1024 else if(strstr(filename,
".fdneut") || strstr(filename,
".FDNEUT")) mode = 7;
1025 else if(strstr(filename,
".unv")) mode = 8;
1026 else if(strstr(filename,
".mphtxt")) mode = 9;
1027 else if(strstr(filename,
".msh")) mode = 14;
1028 else if(strstr(filename,
".plt")) mode = 16;
1031 if(info)
printf(
"Could not determine the filetype based on the suffix\n");
1034 if(info)
printf(
"Filetype determined by suffix: %d\n",mode);
1043 int i,
k,errorstat = 0,
dim;
1044 static int visited =
FALSE;
1065 if(errorstat == 1) {
1069 printf(
"Because file %s didn't exist, it was created for you.\n",
eg.
filesin[nofile]);
1077 errorstat = LoadElmerInput(&(
data[nofile]),boundaries[nofile],
eg.
filesin[nofile],
info);
1135 if(
info)
printf(
"Partitioned solution is fused on-the-fly therefore no other operations may be performed.\n");
1138 if(
info)
printf(
"Finishing with the fusion of partitioned Elmer solutions\n");
1149 if(!errorstat) *nogrids =
MAX(*nogrids,1);
1160 static int visited =
FALSE;
1164 if(inmethod == 1 && outmethod != 1) {
1188 if(grids[k].boundsolid[j] == 2) {
1220 if(outmethod != 1 &&
eg.
dim != 2) {
1223 if(grids[k].dimension == 3 || grids[k].rotate) {
1232 boundaries[
k] = boundaries[j];
1262 if(
nogrids && grids[k].reduceordermatmax) {
1278 ReorderElementsMetis(&
data[k],
TRUE);
1315 static int inmethod,errorstat,
info;
1319 if(info)
printf(
"\nElmerGrid checking filename suffix for file: %s\n",filename);
1329 if(info)
printf(
"Initialized the filetype\n");
1337 int i,
k,inmethod,outmethod,errorstat,nofile;
1339 static char arguments[10][10],**argv;
1341 static int visited =
FALSE;
1352 argv = (
char**) malloc((
size_t) 10*
sizeof(
char*));
1360 if(
info)
printf(
"\nElmerGrid loading data from file: %s\n",filename);
1363 if(inmethod < 0)
return(1);
1377 if(errorstat)
return(errorstat);
1380 if(
info)
printf(
"\nElmerGrid manipulating and importing data\n");
1389 printf(
"No mesh to work with!\n");
1395 for(i=0;i<argc;i++) argv[i] = &arguments[i][0];
1414 if(
info)
printf(
"Done destroying structures\n");
1419 int main(
int argc,
char *argv[])
1432 int main(
int argc,
char *argv[])
1436 static int i,j,
k,l,inmethod,outmethod,errorstat;
1437 static int nofile,
dim;
1438 static Real mergeeps;
1441 if(
info)
printf(
"\nStarting program Elmergrid\n");
1451 if(argc <= 1) Instructions();
1455 else if(argc == 3) {
1461 if(errorstat) Goodbye();
1468 if(!outmethod || !inmethod) {
1469 printf(
"Please define the input and output formats\n");
1474 if(
info)
printf(
"\nElmergrid loading data:\n");
1482 if(errorstat) Goodbye();
1487 if(
info)
printf(
"\nElmergrid creating and manipulating meshes:\n");
1492 PartitionMesh(nofile);
1495 if(
info)
printf(
"\nElmergrid saving data:\n");
1497 for(nofile=0;nofile<
nomeshes;nofile++) {
1499 sprintf(filename,
"%s",prefix);
1501 sprintf(filename,
"%s%d",prefix,nofile+1);
1502 ExportMeshDefinition(inmethod,outmethod,nofile,filename);