Ansys Learning Forum Forums Discuss Simulation LS Dyna Location of results when using python or cmd to call ls-run to calculate k files Reply To: Location of results when using python or cmd to call ls-run to calculate k files

Reno Genest
Ansys Employee

Hello,

I created a short Python program to run LS-DYNA. By default, LS-DYNA will run where the Python script is located and the output files (d3plot, messag, d3hsp, etc.) will be written where the Python script is located.

The solution is to change the directory using os.chdir in your Python script before you call the LS-DYNA solver. Here is an example:

import os
import subprocess
 
os.chdir("D:\KFILES\Cube\Script")
 
subprocess.run(["C:\LS-DYNA_Solvers\SMP_DEV_dp\ls-dyna_smp_d_DEV_116799-gea62947e59_winx64_ifort190.exe", "i=D:\KFILES\Cube\Script\input.k", "ncpu=1", "memory=20m"])
 
#os.system('"C:\LS-DYNA_Solvers\SMP_DEV_dp\ls-dyna_smp_d_DEV_116799-gea62947e59_winx64_ifort190.exe" i=D:\KFILES\Cube\Script\input.k ncpu=1 memory=20m')
 
#result = subprocess.run(["C:\LS-DYNA_Solvers\SMP_DEV_dp\ls-dyna_smp_d_DEV_116799-gea62947e59_winx64_ifort190.exe", "i=D:\KFILES\Cube\Script\input.k", "ncpu=1", "memory=20m"], capture_output=True, text=True)
 
#print(result.stdout)
 
 
You can run LS-DYNA using the subprocess.run() method or the os.system() method. But, subprocess.run() has more options and is recommended here How to execute a Program or System Command from Python - Python Engineer. 
 
 
Let me know how it goes.
 
 
Reno.