-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Adding SpaceClaim/PyMAPDL Tesseract example and docs #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OliverLittlewood
wants to merge
7
commits into
main
Choose a base branch
from
ansys_integration_examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,423
−0
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a515e2
Quick structure outline for docs examples
OliverLittlewood eb327f3
init pymapdl tess
NolanBlack a0a7296
init docs for pymapdl tess
NolanBlack e039583
First 'complete' draft of SpaceClaim tesseract docs
OliverLittlewood da4101f
commit the pymapdl result image
NolanBlack 4840737
Merge branch 'ansys_integration_examples' of https://github.com/paste…
OliverLittlewood d608076
Apply suggestions from Andrins review of SpaceClaim tutorial
OliverLittlewood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
106
docs/content/examples/ansys_integration/pymapdl_tess.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
|  | ||
|
|
||
| *Figure: Element-wise sensitivity gradient (∂compliance/∂ρ) for the cantilever beam test case.* |
71 changes: 71 additions & 0 deletions
71
docs/content/examples/ansys_integration/spaceclaim_tess.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
OliverLittlewood marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ```{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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.