Skip to content

Workshop showcasing design optimization techniques for a motorcycle swingarm using MATLAB and PythonOCC interoperability. Ideal for engineers interested in multiplatform computational design and optimization workflows.

License

Notifications You must be signed in to change notification settings

mathworks/Engineering-Design-Optimization-using-MATLAB-and-Python

 
 

Repository files navigation

Workshop on Engineering Design Optimization using MATLAB® and Python™

View Engineering Design Optimization using MATLAB and Python on File Exchange or Open in MATLAB® Online

Description

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.

Owner/s

Andreas Apostolatos, PhD ([email protected])
María Elena Gavilán Alfonso ([email protected])

Contents

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®

Solid swingarm geometry

 

  • 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

von Mises stresses

 

  • 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®

MATLAB® Python™ Interoperability

 

  • Example4.mlx
    In this example, function patternsearch 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

Optimize Live Task

 

  • Example5.mlx
    This example summarizes the complete workflow into a comprehensive MATLAB® App using the MATLAB® App Designer.

Swingarm Optimization MATLAB® App

 

Concepts

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

Suggested Audience

All engineering disciplines, such as, civil engineers, mechanical engineers, etc.

Workflow

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!

Unit-testing framework

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: MATLAB® Test Manager

 

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)

Release last tested

R2024b

TODO

  • 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)

Revision History

Acknowledgment

The support of Yann Debray regading the MATLAB® Python™ interoperability is kindly acknowledged herein

License

This open-source project is licensed using a BSD license, see file LICENSE.md

Support

Reach out to Andreas Apostolatos, PhD ([email protected]) for support with this project

References

[1] Paviot, T. (2022). "pythonocc". Zenodo. https://doi.org/10.5281/zenodo.3605364


Copyright 2025 The MathWorks, Inc.

About

Workshop showcasing design optimization techniques for a motorcycle swingarm using MATLAB and PythonOCC interoperability. Ideal for engineers interested in multiplatform computational design and optimization workflows.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 69.3%
  • MATLAB 30.7%