This repository contains scripts and utilities to run parametric and genetic algorithm-based finite element analysis (FEA) using FreeCAD. The project is designed to automate the exploration of optimized designs by sweeping parameter values or employing a genetic algorithm to minimize von Mises stress.
- Parametric FEA: Automate parameter sweeps to run FEA on multiple design configurations and analyze the results.
- Genetic Algorithm: Leverage a genetic algorithm to optimize designs based on von Mises stress results.
- FreeCAD Integration: Scripts dynamically interact with FreeCAD, utilizing its Python API for CAD model manipulation and FEA.
- CSV Output: Results are saved in CSV format, including von Mises stress and the corresponding parameters for easy post-analysis.
- Logging: Comprehensive logging to help monitor progress and debug issues.
- Python 3.8+
- FreeCAD 0.21+
The project uses Poetry and Pipenv for dependency management. You can choose either to manage the dependencies.
-
Install Poetry:
curl -sSL https://install.python-poetry.org | python3 -
-
Clone this repository:
git clone https://github.com/pepperumo/FreeCAD-genetic-algorithm_FEA.git cd FreeCAD-genetic-algorithm_FEA
-
Install dependencies using Poetry:
poetry install
-
Activate the environment:
poetry shell
-
Install Pipenv:
pip install pipenv
-
Install dependencies using Pipenv:
pipenv install
-
Activate the environment:
pipenv shell
-
Adjust the
FREECAD_PATH
in the scripts (run_all.py
,genetic_algorithm.py
, etc.) to point to your FreeCAD installation path. -
To run a parametric analysis or genetic algorithm, execute:
python main.py
Choose between
RunAll
orGeneticAlgorithm
methods when prompted.
The parametric analysis will sweep through all specified parameter ranges and save the results to a CSV file.
The genetic algorithm will iterate over generations to minimize von Mises stress, saving the best model configuration and results at the end.
main.py
: Entry point to choose between parametric analysis and genetic algorithm.run_all.py
: Runs the parametric FEA analysis over a range of parameters.genetic_algorithm.py
: Implements the genetic algorithm for design optimization.parametric.py
: Handles high-level parametric FEA functions.freecadmodel.py
: Manages interaction with FreeCAD, including model parameter changes and FEA execution.loghandler.py
: Configures logging.Makefile
: Makefile for automating common tasks.pyproject.toml
: Defines the project's dependencies and setup for Poetry.Pipfile
andPipfile.lock
: Define dependencies for Pipenv.
All logs are stored in freecadparametricfea.log
for debugging and tracking execution. Ensure you check this log if any issues arise during the execution of FEA or genetic algorithm runs.
This project is licensed under the MIT License. See the LICENSE.md
file for more details.