Skip to main content

Physically accurate forward ray tracing for optics simulation and optimization with FreeCAD workbench frontend inspired by the FreeCAD OpticsWorkbench

Project description

Optics Design Workbench

This workbench was inspired by the OpticsWorkbench and aims to extend its functionality towards design and optimization of optical assemblies.

Feel free to ask any question in the forum thread.

Prerequisites

FreeCAD version >=1.0.0, python version >=3.11, python packages numpy, scipy, matplotlib, atomicwrites. A jupyter lab installation is recommended.

Installing the FreeCAD workbench

To make the Optics Design Workbench available in FreeCAD, install it using FreeCAD's built in addon manager.

Sometimes the latest version on github is not immediately recognized by the addon manger. To ensure to update to the latest version it may be necessary to uninstall the workbench, then refresh the local cache and install the workbench again.

Installing for usage in external python shells and jupyter notebooks

To install as a regular python package run

pip install optics_design_workbench

(Note that the package looks very much like a freecad.optics_design_workbench namespace package, however it is uploaded to PyPi just as optics_design_workbench, i.e., not being part of the freecad namespace. The reason for this is that the freecad' package is not pip-installable yet and is therefore difficult to install in virtual environments. The optics_design_workbenchwithout the namespace component does not rely on thefreecad' package, therefore can be installed via pip in any virtual environment without any issue.)

Development installation

Clone this repository, install the python module in development mode using pip install -e .. Create a symlink in your FreeCAD's Mod folder pointing to the directory of the cloned directory. With this setup, changes in the cloned repository folder will be effective immediately when restarting FreeCAD. Avoid using regular PyPi or addon manager installations in parallel with the development installation.

Offline installation

If you want to install without the addon manager, head to the releases section and download the zipped source of your version of choice. Extract the downloaded zip to the Mod folder of your FreeCAD installation. Make sure that the folder containing the init_gui.py is on the third subfolder level below the Mod directory like this:

..../Mod/freecad.optics_design_workbench-1.2.3/freecad/optics_design_workbench/init_gui.py

Getting started with examples

To get started, FCStd files and corresponding jupyter notebooks can be found the examples folder of this repository.

Gaussian beam point source and detector

examples/1-source-and-detector

Ray-fan simulation mode

The ray-fan mode renders rays for cross-sections of the solid angle with a spacing matching the inverse power density of the light source. This mode renders fast and gives a good first impression where the optical power of your sources ends up.

ray-fan mode screenshot

Monte-Carlo simulation mode

In the Monte-Carlo simulation mode, rays are placed randomly in the full solid angle according to the given power density of the light source. If the simulation is run in continuous mode, recorded ray hits will be stored to disk and can be loaded and further analyzed with the accompanying notebook in the example folder.

monte-carlo mode screenshot

Spherical lens and parabolic mirror

examples/2-lens-and-mirror

Any geometric body in FreeCAD can become member of one of the OpticalGroups to turn them into reflective, refractive, absorbing or ray-detecting objects. This example contains spherical lenses and slotted parabolic mirrors, transparent and absorbing detectors. When running the continuous simulation, folders for all objects that have set Store Hits to true will be generated.

lens and mirror screenshot

Geometry parameter optimization

examples/3-parameter-sweeps

All parameters of the FreeCAD model are accessible from an external python shell through the jupyter_utils submodule. The recommended workflow is to use a jupyter notebook for such edits (hence the module name). The example shows a simple spherical lens, the radius of which is optimized to minimize the spot size on a detector.

Troubleshooting

When things don't work as expected first make sure you are actually running want you intend to run and whether the same workbench version is installed on the python and the FreeCAD side. To check this, run

import optics_design_workbench
optics_design_workbench.versionInfo()

in the FreeCAD python shell and

import optics_design_workbench
optics_design_workbench.versionInfo()

in your regular python shell of choice.

Make sure that the workbench versions seen by FreeCAD and by python match and that all the displayed versions and paths match your expectations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optics_design_workbench-0.7.3.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optics_design_workbench-0.7.3-py3-none-any.whl (473.2 kB view details)

Uploaded Python 3

File details

Details for the file optics_design_workbench-0.7.3.tar.gz.

File metadata

  • Download URL: optics_design_workbench-0.7.3.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for optics_design_workbench-0.7.3.tar.gz
Algorithm Hash digest
SHA256 58e42d1429a08c536510bc0ed719f5720e438445d7fe704405a557e204b09c10
MD5 7976097cf9c491f25af8019a98cbdd6f
BLAKE2b-256 fe6cbd481cf19e1d017086b2b8bbb3c8729fba3a1df27638b03d2eeb5ff1bda9

See more details on using hashes here.

File details

Details for the file optics_design_workbench-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: optics_design_workbench-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 473.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for optics_design_workbench-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76434a1c8bb6da0865ec02974be7bf6e264766acf27110f6e6801c96ccc7908b
MD5 01b255eaf7fb0e983a481c44fbc196f3
BLAKE2b-256 a934ed0f80094aced462b158b03d30413d24f3535a0263fefebd8619e85ed781

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page