CreateUNVmesh
Perl script which creates a new unv mesh from an exelem and exnode file. See wiki for exactly how this is done.
CreateUNVmesh.pl
—
Plain Text,
3 KB (3424 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 I-DEAS-UNIVERSAL (unv) 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: ./CreateUNVmesh.pl FILE.exnode FILE.exelem NEWMESH.unv L(R)HS
#
# **** NOTE ****
#
# This is only designed at the time being for 3D volume meshes. It will be easy
# later to make it 1D/2D/3D.
#
####################################################################################
open(INND,$ARGV[0]);
$TmpNodOut = "tmpnode.out";
open(TNO,">",$TmpNodOut);
#
# Place heading on tmpnode.out
#
print TNO " -1\n";
print TNO " 2411\n";
#
# Define number of {N}odes {P}er {E}lement
#
my $npe = 8;
#
# 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] eq 'Node:') {
$nnodes = $foo[2]-1;
$Output1 = sprintf(" %2d 0 0 0\n",$nnodes);
print TNO "$Output1";
} else {
$Output2 = sprintf(" %0.16e %0.16e %0.16e \n",$foo[1],$foo[2],$foo[3]);
print TNO "$Output2";
}
}
}
print TNO " -1\n";
print "Number of total nodes = ",$nnodes,"\n";
close(INND);
close(TNO);
open(INEL,$ARGV[1]);
$TmpElOut = "tmpelem.out";
open(TEO,">",$TmpElOut);
#
# Place heading on tmpelem.out
#
print TEO " -1\n";
print TEO " 2412\n";
#
# Read in Elem and Write to tmpelem.out
#
my $flag = 0;
my $nelems = 0;
$prevline = "Nonsense";
$prntnxtline = 0;
while (<INEL>) {
chomp $_;
@foo = split(/\s+/,$_);
#print $foo[1]," \n";
if ($foo[1] eq 'Element:') {
$flag = 1;
}
if( $flag eq 1 ) {
if($foo[1] eq 'Nodes:') {
$prntnxtline = 1;
}
if($prntnxtline == 1 && $foo[1] ne 'Nodes:') {
$Output3 = sprintf("%10d%10d%10d%10d%10d%10d\n",$nelems-1,115,2,1,7,$npe);
print TEO "$Output3";
if( $ARGV[3] eq 'LHS') {
$TMPLINE=sprintf("%10d",$foo[5]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[6]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[7]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[8]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[1]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[2]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[3]-1);
print TEO "$TMPLINE";
$TMPLINE=sprintf("%10d",$foo[4]-1);
print TEO "$TMPLINE";
}else{
for(my $i=0; $i < 8; $i++) {
$foo[$i+1] = int($foo[$i+1])-1;
$TMPLINE=sprintf("%10d",$foo[$i+1]);
print TEO "$TMPLINE";
}
}
print TEO "\n";
$prntnxtline = 0;
}
if($foo[1] eq 'Element:') {
$nelems = $foo[2];
}
}
}
print TEO " -1\n";
print "Number of elements = ",$nelems+1,"\n";
close(TEO);
close(INEL);
system("cat tmpnode.out tmpelem.out > $ARGV[2]");
system("rm -f tmpelem.out tmpnode.out");
