CreateXDAmesh
A new file for creating an xda mesh from exelem and exnode files. See wiki for exactly how to do this.
CreateXDAmesh.pl
—
Plain Text,
2 KB (2867 bytes)
File contents
#!/usr/bin/perl use locale; # This perl script reads in an exelem file and exnode file and creates a mesh # in the libmesh xda format so that we can run problems meshed by cm in libmesh. # The exnode file must come from a grid-based cmiss problem and then exported as: # # 'fem export point;FILENAME grid offset 0' # # The exelem file must come from the same type of problem (a grid-based FEM problem # uses hexahedral elements) and then exported as # # 'fem export grid:FILENAME libmesh' # # where the libmesh is necessary to only print out some of the information and also # to get the right ordering. # # # Run it as: ./CreateXDAmesh.pl FILE.exnode FILE.exelem NEWMESH.xda ElemType # # (1) Read in node file and strip out node vertices # open(INND,$ARGV[0]); $TmpNodOut = "tmpnode.out"; open(TNO,">",$TmpNodOut); # # Read in Node and Write to tmpnod.out # my $flag = 0; while (<INND>) { chomp $_; @foo = split(/\s+/,$_); if ($foo[1] eq 'Node:') { $flag = 1; } if( $flag == 1 ) { if( $foo[1] ne 'Node:') { print TNO " $foo[1] $foo[2] $foo[3] \n"; } else { $nnodes = $foo[2]; } } } print "Number of total nodes = ",$nnodes,"\n"; close(INND); close(TNO); open(INEL,$ARGV[1]); $TmpElOut = "tmpelem.out"; open(TEO,">",$TmpElOut); # # Read in Elem and Write to tmpelem.out # my $flag = 0; my $nelems = 0; $prevline = "Nonsense"; $prntnxtline = 0; $tmp=0; while (<INEL>) { chomp $_; @foo = split(/\s+/,$_); #print $foo[1]," \n"; if ($foo[1] eq 'Nodes:') { $flag = 1; } if( $flag eq 1 ) { if($foo[1] eq 'Nodes:') { $prntnxtline = 1; } if($prntnxtline == 1 && $foo[1] ne 'Nodes:') { for(my $i=0; $i < 8; $i++) { $foo[$i+1] = int($foo[$i+1])-1; print TEO "$foo[$i+1] "; } print TEO "\n"; $prntnxtline = 0; $tmp = $tmp + 1; } if($foo[1] eq 'Element:') { $nelems = $foo[2]; } } } print "Number of elements = ",$nelems,"\n"; close(TEO); close(INEL); # # Create the new libmesh xda file format # # First open file open(XDA,">","temp.xda"); $elemwts = $nelems*8; print XDA "DEAL \n"; print XDA "$nelems # Num. Elements\n"; print XDA "$nnodes # Num. Nodes\n"; print XDA "$elemwts # Sum of Element Weights\n"; print XDA "1 # Num. Boundary Conditions\n"; print XDA "65536 # String Size (ignored)\n"; print XDA "1 # Num. Element Blocks (ignored)\n"; print XDA "$ARGV[3] # Element types in each block.\n"; print XDA "$nelems # Num. of elements in each block.\n"; print XDA "Id String\n"; print XDA "Title String\n"; close(XDA); system("cat temp.xda tmpelem.out tmpnode.out > $ARGV[2]"); system("rm -f temp.xda tmpelem.out tmpnode.out");