Inspiration

In engineering, there is a massive disconnect between how we design objects (CAD software) and how we simulate their physical behavior (FEA/CFD software). Writing a simulation usually requires thousands of lines of boilerplate code just to define a simple geometry and its boundary conditions. I was inspired to create a Domain-Specific Language (DSL) that bridges this gap: a simple, human-readable language that allows an engineer to define 3D geometry and thermal constraints in plain text, which the engine then compiles into real 3D models and high-performance physics simulations.

What it does

The Physics-Informed Generative Design DSL allows users to write a declarative script to define mechanical parts (boxes, cylinders, materials) and material interfaces with thermal constraints.

When a user runs the script through the Streamlit web interface, the engine:

  1. Parses the text into a structured Python object graph.
  2. Generates precise 3D CAD files (.step and .stl) for download.
  3. Routes the thermal constraints to a custom finite-difference solver.
  4. Generates a visual heatmap of the transient temperature distribution across the interface.

How I built it

I built the engine in four distinct layers:

The Language Layer: I used textX, a Python meta-language, to define the grammar and generate the parser.

  • The Interpreter Layer: A custom Python class that walks the AST (Abstract Syntax Tree) and routes the parsed objects to the appropriate backend.
  • The CAD Layer: I used CadQuery to translate the parsed geometric variables into precise 3D B-Rep solids.
  • The Performance Layer: Python is too slow for iterative finite-difference inner loops. I wrote the thermal diffusion kernel in C, compiled it into a shared library, and bridged it to Python using the standard library's ctypes module.
  • The UI: I used Streamlit to host the application on the cloud, with Matplotlib and PyVista for visualization.

Challenges I ran into

Strict FFI Contracts: Bridging Python and C is dangerous. C assumes row-major, C-contiguous memory layouts. I had to enforce strict type and memory checks in the Python wrapper to prevent pointer corruption and segmentation faults.

Cloud Deployment of C Code: Deploying to Streamlit Cloud (which runs Linux) meant my Windows .dll wouldn't work. I had to write a dynamic compilation script inside the app that uses subprocess to compile the C code into a Linux .so file the moment the app boots.

System Dependencies: OpenCascade (the C++ engine behind CadQuery) requires specific Linux graphics libraries (libgl1, libglib2.0-0, etc.) to run on headless cloud servers. Figuring out the modern Debian package dependencies was a headache, but adding a packages.txt file solved it.

Accomplishments that I am proud of

I am incredibly proud of the test suite. The project has 20 passing tests covering the parser, the interpreter, and the C-bridge. One specific test validates my custom C kernel against a pure NumPy reference implementation to a precision of 1e-12. This proves the native code is both fast and mathematically correct. I'm also proud of the CFL stability condition implementation, which calculates a dynamically safe time-step to prevent the explicit finite-difference scheme from blowing up.

What I have learned

This project pushed my understanding of compiler design and foreign function interfaces (FFI) to the next level. I learned how to design a grammar, generate a parser, and safely manage memory across two different programming languages. I also learned a lot about deploying complex, heavy scientific Python libraries (like CadQuery and PyVista) to serverless cloud environments.

What's next for Physics-Informed Generative Design DSL

The current grammar supports basic primitives, but the architecture is highly extensible. Next, I want to:

  1. Expand the grammar to support boolean operations (e.g., subtracting a cylinder from a box to create mounting holes).

  2. Add a structural mechanics module (stress/strain FEA) to complement the thermal solver.

  3. Introduce a materials database so users can simply type material: copper and the engine automatically pulls the correct density, thermal conductivity, and specific heat capacity.

  4. Eventually integrate the Poisson-Schrödinger electrostatics solver to model quantum mechanical transport at the interface.

Built With

Share this project:

Updates

Submission history