close


Packing LS-DYNA Input Files


In these days, a finite element model consists of several INCLUDE files either relative or absolute. When collaborating with other people, it is very difficult to remember sending the included files and also if we do remember, it is cumbersome if not difficult to find them and zip them as one file. I recently encountered this problem and wrote a simple utility in PYTHON to make this a little easier. Once you download this file, you simply invoke this using “pack_dyna main_input_file.k” and it handles all the rest of packing to give you one BZIP2 file to send to your contacts. In some cases, you may want to ignore absolutely references files (/some/path/to/a/include/file.k). To enable this, you can set the variable RELATIVE_FILES_ONLY to 1 which will cause the program to include only relatively included files (path/to/a/relative/file.k).

I must credit Dr. Brian Wainscott who was kind to guide me into using Python.

Download Link: pack_dyna.py

#!/usr/bin/python
# Utility to pack files for a LS-DYNA run
# Author: Suri Bala

import os,sys

RELATIVE_FILES_ONLY=0

if len(sys.argv) == 1:
print "Usage %s main_file.k" % sys.argv[0]
sys.exit()

MAIN_FILE=sys.argv[1]
if os.path.exists(MAIN_FILE)==0:
print " File %s does not exist" % MAIN_FILE
print " Exiting ...."
sys.exit()

JOB_NAME = MAIN_FILE.split(".").pop(0)
FILES=[]

FILES.append(MAIN_FILE)

def process_file (NAME):
file=open(NAME)
for line in file:
nline=line.strip("\n")
if len(nline)>0 and nline[0]=="*" and nline[0:4]=="*inc" or nline[0:4]=="*INC":
line=file.next().strip("\n")
if os.path.exists(line):
if RELATIVE_FILES_ONLY and line[0]!="/":
FILES.append(line)
else:
FILES.append(line)
process_file(line)

process_file(MAIN_FILE)

FILE_NAME=""
for f in FILES:
FILE_NAME+=" "+f

os.system("tar -cf "+JOB_NAME+".tar "+FILE_NAME)
os.system("bzip2 "+JOB_NAME+".tar")

  • Carlos Lois says:

    Hello Suri, I normally use a lot of includes due to the versitility to change quicly component meshes, spc, etc.

    When I want to send it in one package I use Ls-prepost to save it in a single .k file as lates versions allows you to save in 2 ways:

    -If you want to keep the include structure click in BySubSystem and save
    -If you want to pack all the includes in a single .k just save normally.

    Is this similar to the program you are proposing? It seems like a unix based program and I normally use windows.

    Carlos Lois

  • Suri Bala says:

    Hi Carlos,

    It is similar to the a GZIP or ZIP program but it ensures that all the files referenced by INCLUDE keywords are included in the package.

    Suri

Leave a Reply

Your email address will not be published. Required fields are marked *


*