Python in ILIAD

Dec 28, 2021

Python is one of the most popular programming languages in use today. Because it is high-level, interpreted, easy to learn, and free to use, Python has seemingly become the common language shared by engineers, scientists, and technically inclined individuals seeking to leverage the power of computer scripting without the steep learning curve of many classic programming languages.  

Figure 1: A typical optimization workflow using the Python Equation component.   

ILIAD’s Python Equation component offers a native interpreter that allows users to easily access the full power of Python directly in ILIAD! Simply write a Python script in the Component Editor tab and ILIAD instantly has complete access to all your variables so they may be used in your optimization and design of experiments workflows.  

Figure 2: Diagram of a simplified catapult launch angle optimization problem. 

As an example, let’s say we are operating a 2m tall catapult and want to find the best angle (𝜃𝜃) at which to release our projectile so that it travels the furthest. If the projectile is dense, we can neglect drag and approximate that it will land after 𝑡𝑐𝑟𝑖𝑡=𝑣0sin𝜃+𝑣0sin𝜃+4𝑔‾‾‾‾‾‾‾‾‾‾‾‾√𝑔tcrit=v0sin⁡𝜃+v0sin⁡𝜃+4gg 

seconds. During this time, it will travel a horizontal distance of 𝑥𝑓=𝑣0cos𝜃𝑡𝑐𝑟𝑖𝑡xf=v0cos⁡𝜃tcrit 

meters, where 𝑣0=20𝑚/𝑠v0=20m/s is the initial launch speed and 𝑔=9.8 𝑚/𝑠2g=9.8 m/s2 is the constant of gravitational acceleration.  

Figure 3: The Python Equation component configured to calculate the travel distance as a function of the launch angle. 

Using the workflow shown in Figure 1, all we need to do is navigate to the component editor of the Python Equation component, write our script on the text editor on the right and declare our optimization variables in the center window where they are made available for use in the rest of the workflow. Easily check your script by clicking the Test button below the text editor to verify it is bug-free. Using ILIAD’s Optimization component to maximize the maximum travel distance with respect launch angle, we find that in this scenario, the best angle is 0.618 radians or 35° which will give a projectile distance of 57 meters! 

Check back in weekly for tips, tricks and interesting applications of OmniQuest software!