Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/content/examples/ansys_gallery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Ansys Integration

```{toctree}
:name: ansys-gallery
:caption: Ansys Gallery
:maxdepth: 2
:hidden:
:glob:
ansys_integration/spaceclaim_tess.md
ansys_integration/pymapdl_tess.md
```

This is a gallery of Tesseract examples integrating that with Ansys products in many different ways, demonstrating the versatility that you can then use to build your own Tesseracts.

You can also find these Ansys Tesseracts in the `examples/ansys_integration` directory of the [code repository](https://github.com/pasteurlabs/tesseract-core).


::::{grid} 2
:gutter: 2

:::{grid-item-card} Spaceclaim
:link: ansys_integration/spaceclaim_tess.html

A Spaceclaim Tesseract.
:::
:::{grid-item-card} PyMAPDL
:link: ansys_integration/pymapdl_tess.html

Draft PyMAPDL md.
:::

::::
106 changes: 106 additions & 0 deletions docs/content/examples/ansys_integration/pymapdl_tess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# ANSYS MAPDL SIMP Compliance

## Context

Example that wraps ANSYS MAPDL as a differentiable Tesseract for SIMP (Solid Isotropic Material with Penalization) topology optimization.
The Tesseract computes structural compliance using finite element analysis and provides analytical sensitivities for gradient-based optimization.

## Prerequisites

This example requires a running ANSYS MAPDL server accessible via gRPC:

```bash
# Linux
/usr/ansys_inc/v241/ansys/bin/ansys241 -grpc -port 50052

# Windows
"C:/Program Files/ANSYS Inc/v241/ansys/bin/winx64/ANSYS241.exe" -grpc -port 50052
```

## Example Tesseract (examples/ansys_integration/pymapdl_tess)

### Core functionality --- schemas and `apply` function

The Tesseract accepts a hexahedral mesh, density field, and boundary conditions as inputs. The density field `rho` is marked as `Differentiable` to enable gradient computation:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: HexMesh
:language: python
```

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: InputSchema
:language: python
```

The outputs include compliance (the optimization objective), element-wise strain energy, and sensitivity values:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: OutputSchema
:language: python
```

The `apply` function connects to MAPDL, creates the mesh, assigns SIMP-interpolated materials based on density, applies boundary conditions, solves the static analysis, and extracts results:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: apply
:language: python
```

### SIMP material interpolation

The solver creates a unique material for each element with properties scaled by the density field using the SIMP formula:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: SIMPElasticity._define_simp_materials
:language: python
```

This interpolation scheme penalizes intermediate densities, encouraging binary (solid/void) designs in topology optimization.

### Vector-Jacobian product endpoint

For compliance minimization, the adjoint solution equals the negative displacement field. This allows computing sensitivities analytically without an explicit adjoint solve:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: SIMPElasticity._calculate_sensitivity
:language: python
```

The cached sensitivity is loaded during the VJP computation and multiplied by the upstream gradient:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: vector_jacobian_product
:language: python
```

### Abstract evaluation

The `abstract_eval` function computes output shapes based on input shapes without running the ANSYS solver, enabling static analysis and memory pre-allocation:

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/tesseract_api.py
:pyobject: abstract_eval
:language: python
```

## Demo script

The demo script (`examples/ansys_integration/pymapdl_tess/demo.py`) shows a complete workflow for a cantilever beam problem:

The demo requires you set environment variables pointing to the MAPDL server:

```bash
export MAPDL_HOST=192.168.1.100
export MAPDL_PORT=50052
```

```{literalinclude} ../../../../examples/ansys_integration/pymapdl_tess/demo.py
:pyobject: main
:language: python
```

The script verifies correctness by checking that total strain energy equals half the compliance, which holds for linear elastic problems.

![Cantilever beam sensitivity analysis](pymapdl_simp_compliance.png)

*Figure: Element-wise sensitivity gradient (∂compliance/∂ρ) for the cantilever beam test case.*
71 changes: 71 additions & 0 deletions docs/content/examples/ansys_integration/spaceclaim_tess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# SpaceClaim Tesseract

## Context
Within the Ansys product collection there are many great ways to generate geometries for Computer Aided Engineering (CAE) simulations. Additionally, complex CAD models are often imported from parametric CAD software and require pre-processing by e.g. extracting a fluid volume for simulatuion, or naming domain faces such that appropriate boundary conditions can be applied.

SpaceClaim is commonly used to perform these pre-procsesing actions, and additionally can be used to generate geometry. Here the use of SpaceClaim and automated SpaceClaim scripts (`.scscript`) will be demonstrated from within a Tesseract.

## What is different about this Tesseract?

Tesseracts are most commonly used in their self-contained built form; however, in this case we want SpaceClaim to be called from within the Tesseract, and cannot containerize SpaceClaim itself. To allow us to use SpaceClaim (or any other propriatary software that cannot be containorized) we will be demonstrating a runtime Tesseract with the `serve` functionality from `tesseract-core[runtime]`. This will allow us to setup a Tesseract on a machine with Ansys products and licensing, and then make requests to this Tesseract via HTTP.

## Setting up a Tesseract Runtime Server

When creating a Tesseract you should have a Tesseract directory with three files like so:

```bash
$ tree examples/helloworld
examples/helloworld
├── tesseract_api.py
├── tesseract_config.yaml
└── tesseract_requirements.txt
```

You can learn about Tesseract basics [here](../../introduction/get-started.md). Normally this directory would be passed to `tesseract build`, but instead we are going to make use of `tesseract-runtime` which will provide us an interface with the Tesseract:

```bash
pip install tesseract-core[runtime]
```

With this installed, and a open port of your choice, from within the Tesseract directory we can execute:

```bash
tesseract-runtime serve --port <port_number> --host 0.0.0.0
```

The result should be an active Tesseract Runtime Server that we can now make requests too:

```bash
$ tesseract-runtime serve --port 443 --host 0.0.0.0
INFO: Started server process [14888]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:443 (Press CTRL+C to quit)
```

## Example Tesseract (`examples/ansys_integration/spaceclaim_tess`)

For this example we are looking at the SpaceX Grid Fin geometry demonstrated in this [demo](https://si-tesseract.discourse.group/c/showcase/11). This specific example requires some dependencies, so if you would like to follow along copy the files from `examples/ansys_integration/spaceclaim_tess` and create a new python environment, then:

```bash
pip install tesseract-core[runtime] trimesh
```



```{literalinclude} ../../../../examples/ansys_integration/spaceclaim_tess/tesseract_api.py
:language: python
:pyobject: run_spaceclaim
```

Why spaceclaim

Wrapping products that cannot be containorized

Runtime tesseracts with serve

Connecting to a runtime tesseract

How we choose inputs and outputs

See how this example is used in a DEMO
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ content/using-tesseracts/advanced.md

content/examples/example_gallery.md
content/demo/demo.md
content/examples/ansys_gallery.md
Tesseract Community Showcase <https://si-tesseract.discourse.group/c/showcase/11>
```

Expand Down
Loading
Loading