Automating EDEM Simulations runs and Iota Analyses

This is an example of a script that runs of a list of EDEM simulations and as soon as each simulation finishes, it launches the coarse-graining analysis based on a base coarse-graining settings. Note that the EDEM simulation and coarse-graining is also launched for the base scenario where the base coarse-graining settings are taken from.

''' Given a list of EDEM simulations that have been already set in EDEM, a Iota project, a Iota scenario (base scenario)
     where coarse-graining settings has been set and a list if scenarios names, for each EDEM simulation and scenario, 
     run the EDEM simulation and once the simulation is over, automatically clone the coarse-graining settings from 
     the base scenario and run the coarse-graining analysis'''

import sys                              
import os
import subprocess
import iota
sys.path.append(os.getenv('IOTA_PATH'))                                         # Add iota directory to Python paths

username = 'stephen'                                                            # Set Iota username
home_path = 'C:/Users/stephen/'                                                 # Set user's home directory


### Settings for EDEM executable
EDEM_path='C:/Program Files/DEM Solutions/EDEM 2018/bin/edem.exe'               #Path to EDEM executable on your machine

### Setttings for bacth cloning and setting coarse-graining
project_name = 'Backhoe optimization'                                 #Name of the project to work with
base_scenario = 'Design Alpha'                                        #Name of the scenario that contains the coarse-graning settings to be cloned
scenarios_names = ['Design_Alpha', 'Design Beta','Design Gamma']      #Name for scenarios to be post-processed
input_EDEM_Data = ['C:/Users/stephen/Backhoe_simulations/Design_Beta.dem',  
    'C:/Users/stephen/Backhoe_simulations/Design_Gamma.dem']          #Input DEM simulation files to be run and post-processed.
####################


my_session = iota.session(username,home_path + 'ParticleAnalytics/config.ini')  # Start new session

pr = my_session.get_project(project_name)                              #Get the selected project to work on

base_sc = pr.get_scenario(base_scenario)                         #Load the scenario that contains coarse-graining settings to be cloned
base_cg_settings = base_sc.get_coarse_graining_settings()        #Get the coarse-graining settings to be cloned for the other scenarios

## Batch loop starts here
for sc_name, simu_EDEM in zip(scenarios_names,input_EDEM_Data):       #For each scenario name and input EDEM data

    #Run EDEM simulation

    print('Running EDEM simulation for scenario {}'.format(sc_name))
    edem_command = ['edem.exe','--console', '-i', simu_EDEM]
    print('Running EDEM for scenario {}'.format(sc_name))
    p=subprocess.Popen(edem_command, executable=EDEM_path)                 #EDEM simulation is launched
    p.communicate()
    print('EDEM simulation for scenario {} finished'.format(sc_name))

    if sc_name != base_scenario:                                          # If the scenario is not the base scenario  
        sc = pr.add_scenario(sc_name)                                     #Create a new scenario

        ### Copy base settings and modify
        for_new_scenario = cg_base.as_dict().copy()                       #Copy coarse-graning settings from base scenario
        for_new_scenario['scenario'] = sc.id                              #Set the id of the new scenario
        for_new_scenario['output']['name'] = sc.name                      #Set the name of the output datasets to the new of the scenario
        for_new_scenario['output']['directory'] = sc.directory            #Set the output directory to the directory of the new scenario
        for_new_scenario['input']['data']['edem_filename'] = simu_EDEM    #Set the input DEM data to be processed in the new scenario

        ### Save the updated coarse-graining setting to the scenario
        cg_settings = sc.get_coarse_graining_settings()                   #Get the coarse-graining settings of the new scenario before updating
        cg_settings._dict = for_new_scenario                              #Update the coarse-graining settings of the new scenario
        cg_settings.set()                                                 #Save the updated coarse-grainings to the new scenario

    else:                                                                 #else the scenario to post-processed in the base scenario 
        sc = sc_base

    ### Run coarse-graining for the scenario
    print('Running coarse-graining fro scenario {}'.format(sc.name))
    sc.run_coarse_graining()
    print('Scenario {} finished'.format(sc.name))

print('All finished')

Last updated

Was this helpful?