This notebooks run multiple simulations¶
Warning: path doesn´t accept space.¶
In [1]:
Copied!
import os
import subprocess
solver = "C:\LSDYNA\program\ls-dyna_smp_s_R11_1_0_winx64_ifort160.exe"
ncpu = 2
import os
import subprocess
solver = "C:\LSDYNA\program\ls-dyna_smp_s_R11_1_0_winx64_ifort160.exe"
ncpu = 2
In [5]:
Copied!
main_directory= os.getcwd()
sub_directory = list(filter(os.path.isdir, os.listdir(os.curdir))) # List of sub_directories
sub_directory.remove('_env') # remove _env for running
print(sub_directory)
main_directory= os.getcwd()
sub_directory = list(filter(os.path.isdir, os.listdir(os.curdir))) # List of sub_directories
sub_directory.remove('_env') # remove _env for running
print(sub_directory)
['C0_C2_EXTENSION_50F', 'C0_C2_EXTENSION_50M', 'C0_C2_FLEXION_50F', 'C0_C2_FLEXION_50M', 'C1_C2_EXTENSION_50F', 'C1_C2_EXTENSION_50M', 'C1_C2_FLEXION_50F', 'C1_C2_FLEXION_50M', 'C2_C3_EXTENSION_50F', 'C2_C3_EXTENSION_50M', 'C2_C3_FLEXION_50F', 'C2_C3_FLEXION_50M', 'C3_C4_EXTENSION_50F', 'C3_C4_EXTENSION_50M', 'C3_C4_FLEXION_50F', 'C3_C4_FLEXION_50M', 'C4_C5_EXTENSION_50F', 'C4_C5_EXTENSION_50M', 'C4_C5_FLEXION_50F', 'C4_C5_FLEXION_50M', 'C5_C6_EXTENSION_50F', 'C5_C6_EXTENSION_50M', 'C5_C6_FLEXION_50F', 'C5_C6_FLEXION_50M', 'C6_C7_EXTENSION_50F', 'C6_C7_EXTENSION_50M', 'C6_C7_FLEXION_50F', 'C6_C7_FLEXION_50M', 'C7_T1_EXTENSION_50F', 'C7_T1_EXTENSION_50M', 'C7_T1_FLEXION_50F', 'C7_T1_FLEXION_50M']
In [7]:
Copied!
for i in range(0,len(sub_directory)):
full_path = os.path.join(main_directory, sub_directory[i])
os.chdir(full_path)
file_list= os.listdir(full_path) # get list of file in folder
for key_file in [file for file in file_list if file.endswith("key")]: # loop into the file_list to look for file ending with .key
run_path= os.path.join(full_path, key_file)
assert os.path.isfile(run_path), "Wrong path"
subprocess.call('r{} i={} ncpu={} memory=20m'.format(solver, run_path,ncpu)) # remeber to change the path of ls-dyna .exe.
# Chekc the messag file to assess the termination
fileObject = open("messag", "r")
data = fileObject.read()
if('N o r m a l t e r m i n a t i o n' in data):
print('{} - Successfull'.format(sub_directory[i]))
elif('E r r o r t e r m i n a t i o n' in data):
print('{} - Failed'.format(sub_directory[i]))
else:
print('No! Error -{}'.format(i+1))
for i in range(0,len(sub_directory)):
full_path = os.path.join(main_directory, sub_directory[i])
os.chdir(full_path)
file_list= os.listdir(full_path) # get list of file in folder
for key_file in [file for file in file_list if file.endswith("key")]: # loop into the file_list to look for file ending with .key
run_path= os.path.join(full_path, key_file)
assert os.path.isfile(run_path), "Wrong path"
subprocess.call('r{} i={} ncpu={} memory=20m'.format(solver, run_path,ncpu)) # remeber to change the path of ls-dyna .exe.
# Chekc the messag file to assess the termination
fileObject = open("messag", "r")
data = fileObject.read()
if('N o r m a l t e r m i n a t i o n' in data):
print('{} - Successfull'.format(sub_directory[i]))
elif('E r r o r t e r m i n a t i o n' in data):
print('{} - Failed'.format(sub_directory[i]))
else:
print('No! Error -{}'.format(i+1))
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) Cell In[7], line 13 11 subprocess.call('{} i={} ncpu={} memory=20m'.format(solver, run_path,ncpu)) # remeber to change the path of ls-dyna .exe. 12 # Chekc the messag file to assess the termination ---> 13 fileObject = open("messag", "r") 14 data = fileObject.read() 15 if('N o r m a l t e r m i n a t i o n' in data): File c:\Users\chiarar\Anaconda3\envs\vivaplus\lib\site-packages\IPython\core\interactiveshell.py:282, in _modified_open(file, *args, **kwargs) 275 if file in {0, 1, 2}: 276 raise ValueError( 277 f"IPython won't let you open fd={file} by default " 278 "as it is likely to crash IPython. If you know what you are doing, " 279 "you can use builtins' open." 280 ) --> 282 return io_open(file, *args, **kwargs) FileNotFoundError: [Errno 2] No such file or directory: 'messag'
In [ ]:
Copied!