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
December 13, 2024 at 8:30 pm
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.