Skip to main content

freecadparametricfea

A flexible parametric FEA library based on FreeCAD, currently supporting FreeCAD 0.20 on Windows.

If you have 20 minutes I recommend the video tutorial on the @engineeringmaths Youtube channel.

Warning: this project is very early release, and should not be used for any serious structural analysis. It is aimed at hobbyists and makers

Quickest start

Create a Python 3.8 virtual environment:

pipenv --python 3.8

Install the latest version from pypi:

pipenv install freecadparametricfea

then run any of the examples inside the examples folder

Quick start

Create a FreeCAD part and assign names to the constraints that you want to change. You need to set up a FEA analysis as well, I have tested this using CalculiX and Netgen.

Then in a script, or on the command line, run:

from FreecadParametricFEA import parametric
import numpy as np

# initialise a parametric FEA object
fea = parametric()

# load the FreeCAD model
fea.set_model("your-part-here.fcstd")

# list the parameters to sweep:
fea.set_variables(
    [
        {
            "object_name": "CutsSketch", # the object where to find the constraint
            "constraint_name": "NotchDistance", # the constraint name that you assigned 
            "constraint_values": np.linspace(10, 30, 5), # the values you want to check
        },
        {
            "object_name": "CutsSketch",
            "constraint_name": "NotchDiam",
            "constraint_values": np.linspace(5, 9, 5),
        },
    ]
)

# run and save the results (will return a Pandas DataFrame)
results = fea.run_parametric()

# plot the results
fea.plot_fea_results()

Feeling fancy

Custom outputs

The default is to export the max Von Mises stress and max displacement values. You can also specify your own values and data reduction function like this:

fea.set_outputs([
        {
            "output_var": "vonMises",
            "reduction_fun": np.median,
        },
        {
            "output_var": "vonMises",
            "reduction_fun": lambda v: np.percentile(v, 95),
            "column_label": "95th percentile"
        }
    ])

Changing materials

You can specify any material that you can find in the FreeCAD FEA material selection dropdown; just refer to it by its name:

fea.set_outputs([
    {
        "object_name": "MaterialSolid",  # the object where to find the constraint
        "constraint_name": "Material",  # the constraint name that you assigned
        "constraint_values": ["Aluminium-Generic", "Steel-Generic"],
    },
])

Different names for CCX solver and CCX results

Renaming the CCX solver and results won't affect the solution, but if you're having trouble running the analysis you can set them yourself just before run_parametric():

# in case you need to explicitly set the CalculiX results object and the solver name
fea.setup_fea(fea_results_name="CCX_Results", solver_name="SolverCcxTools")

Exporting data

You can export individual ParaView files using:

results = fea.run_parametric(export_results=True, output_folder="path/to/my/results")

Or just save the results dataframe in a .csv, json or serialised pickle object:

fea.save_fea_results("results.csv")
fea.save_fea_results("results.json", mode="json")
fea.save_fea_results("results.pickle", mode="pickle")

... or even take a look at the parameters matrix before running any analysis:

results = fea.run_parametric(dry_run=True)

Custom FreeCAD path

If you have multiple installations of FreeCAD or are using a system other than Windows (as of version <=0.3) you have to specify the path to FreeCAD manually in the call to parametric:

# you can manually specify the path to FreeCAD on your system:
FREECAD_PATH = "C:/Program Files/FreeCAD 0.20/bin"
fea = parametric(freecad_path=FREECAD_PATH)

Limitations and caveats

As of 0.3:

  • this has been tested on FreeCAD 0.20, on Windows only, but you can try other platforms
  • only Netgen meshes are supported
  • Only static FEM analysis has been tested

Contributing

I have created this for hobby and personal use, as I was interested in learning more about FreeCAD and writing Python modules. There are a lot of things that I would like to fix, if you want to get involved have a look at the open issues and send me a message if you have any questions.

Metadata

Release files for freecadparametricfea 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for freecadparametricfea 0.3
File Size Uploaded
freecadparametricfea-0.3.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for freecadparametricfea 0.3
File Interpreter ABI Platform
freecadparametricfea-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 41.1 kB

Release files / freecadparametricfea-0.3.tar.gz

Download URL freecadparametricfea-0.3.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c42cb799fe0487d8cf551e161af81f2d96b5f1e98f6fcae8165d3a4ed1cdb7f4
BLAKE2b-256 checksum
How to use checksums
2d671884b6cf5cb9883cf13eae394547ccebd448d42ebbcca9d504041f5dc476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.8.10 Windows/10

Release files / freecadparametricfea-0.3-py3-none-any.whl

Download URL freecadparametricfea-0.3-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23cfe33f322f3684db35657651cfbb33d5ed87a5481ee80675cb294ab46dae7f
BLAKE2b-256 checksum
How to use checksums
3d5b503802d7862bda2df5fd827c675fe1de5cb521d4fb6e0a4758c004837bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.8.10 Windows/10

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page