This workshop on Engineering Design Optimization using MATLAB® and Python™ addresses the shape optimization of mechanical components for strength. Python™ package PythonOCC [1] (Retrieved from https://github.com/tpaviot/pythonocc-core
), which is under the LPGLv3 license, is used to read-in and manipulate geometries, whereas MATLAB® is used for the structural analysis and optimization.
This interactive workshop uses extensively the MATLAB® Live® Editor, the Partial Differential Equation Toolbox™, and the Global Optimization Toolbox™ for the development and the presentation. More specifically, the Visualize PDE Results Live Task is used for the visualization of the von Mises stresses and the Optimize Live Task is used for the shape optimization for strength.
Andreas Apostolatos, PhD ([email protected]
)
María Elena Gavilán Alfonso ([email protected]
)
The repository contains the following Live Scripts and folders:
-
Engineering-Design-Optimization-using-MATLAB-and-Python.prj
This is the MATLAB® project file which sets up all necessary dependencies including the installation of PythonOCC -
Main.mlx
This is a reference document that can be used to navigate to the rest of the Live Scripts in the repository -
main_unitTests.mlx
This is the Live Script that executes the unit tests -
Example1.mlx
This example highlights the necessary workflows for importing standard Computer-Aided Design (CAD) file formats (e.g.IGES
,STEP
-files) in MATLAB®
Example2.mlx
This example focuses on the use of the Partial Differential Equation Toolbox™ for the prediction of the mechanical behavior of a motorcycle swingarm under usual loading conditions. Moreover, this example demonstrates how the cost function for strength can be formulated leveraging appropriate Application Programming Interfaces (APIs) from the Partial Differential Equation Toolbox. The Visualize PDE Results Live Task is used for the visualization of the von Mises stresses across the component
Example3.mlx
This example introduces the MATLAB® PythonOCC Interoperability. Using sliders and other interacting elements of the MATLAB® Live Editor, the example demonstrates how the designer can modify the geometry of the motorcycle swingarm by directly calling PythonOCC APIs from within MATLAB®
Example4.mlx
In this example, functionpatternsearch
through the Optimize Live Task is leveraged to perform shape optimization of the motorcycle swingar. A selected sharp edge is filtered and then the optimization is performed for reduction of the strain energy aiming to lower the local stress concentration and increase structural strength of the component
Example5.mlx
This example summarizes the complete workflow into a comprehensive MATLAB® App using the MATLAB® App Designer.
Finite element analysis, MATLAB® Python™ interoperability, modeling via Computer-Aided Design (CAD), CAD import, programmatic CAD manipulation, shape optimization for strength, motorcycle swingarm, Visualize PDE Results Live Task, Optimize Live Task, MATLAB® App Designer, unit-testing, MATLAB® Projects, Git-integration
All engineering disciplines, such as, civil engineers, mechanical engineers, etc.
Firstly, open the project file Engineering-Design-Optimization-using-MATLAB-and-Python-R25a.prj
to have all the folder dependencies resolved and PythonOCC installed. Then, open Live Script Main.mlx, go to Section Quick guide, select any of the desirable Live Scripts from the list, and hit Run!
To interactively run the associated unit tests of this MATLAB® Project, the MATLAB® Test Manager from the Project Tools in the project toolstrip can be leveraged, see the following screenshot:
Alternatively, the unit tests for this courseware can be executed programmatically by using the following commands in the Command Window of MATLAB®
>> suite = matlab.unittest.TestSuite.fromProject("Engineering-Design-Optimization-using-MATLAB-and-Python.prj");
>> run(suite)
R2024b
- Allow user to select where to download the Miniforge executable, which Python installation to be used, and in which Python installation PythonOCC should be installed
- Allow an option to use Anaconda instead of conda-forge (consider using option 'conda-content-trust' to verify the signatures of the packages prior to installation)
The support of Yann Debray regading the MATLAB® Python™ interoperability is kindly acknowledged herein
This open-source project is licensed using a BSD license, see file LICENSE.md
Reach out to Andreas Apostolatos, PhD ([email protected]
) for support with this project
[1] Paviot, T. (2022). "pythonocc". Zenodo. https://doi.org/10.5281/zenodo.3605364
Copyright 2025 The MathWorks, Inc.