A native, high-performance differentiable structural form-finding and multi-objective optimization engine written in Rust with C# Grasshopper integration for Rhino 8 & 9.
diff_soma is a native standalone library designed to facilitate interactive, real-time structural design and gradient-based optimization. By implementing both the Force Density Method (FDM) and an Analytical Adjoint State Method natively in Rust, the engine calculates exact mathematical gradients for multi-objective structural layouts in microseconds. It compiles to a lightweight dynamic library, enabling direct, low-latency integration within desktop CAD platforms like Rhino and Grasshopper without requiring external runtime environments or inter-process communication (IPC) overhead.
- Non-Linear Forward Pass with Dynamic Self-Weight: Integrates structural dead load updating along the Z-axis based on solved member lengths, resolved via a fast-converging fixed-point iteration loop.
-
Analytical Adjoint Gradients: Computes exact gradients of the multi-objective loss with respect to both force densities (
$q$ ) and support coordinates ($x_c$ ) in$O(E)$ time, utilizing explicit mathematical derivations instead of automatic differentiation packages. -
Block-Triangular Adjoint System: Leverages the block upper-triangular structure of the self-weight Jacobian to solve the coupled 3D adjoint state equations sequentially (back-substitution), bypassing the need for assembling a full
$3N_f \times 3N_f$ coupled system. -
Matrix-Free Preconditioned Conjugate Gradient (PCG): Employs a native Jacobi-preconditioned CG solver for symmetric positive-definite linear subsystems. It evaluates matrix-vector products directly from edge connectivity arrays, requiring
$O(1)$ auxiliary memory. - Multi-Objective Loss Formulation: Supports simultaneous optimization of coordinate-wise target geometry matching, projection onto curved parametric target surfaces (Spherical Domes and Hyperbolic Paraboloids), total structural load-path (material volume), discrete Laplacian coordinate smoothing, member length equalization, and quad-panel coplanarization.
In the Force Density Method (FDM), the nodal equilibrium equations are written as:
Where
A fixed-point iteration loop resolves this non-linear dependency in
Let
Where diff_soma solves the coupled 3D adjoint state equations sequentially (back-substitution) rather than assembling a full
- Solve the non-symmetric system
$(\mathbf{A} + \mathbf{K}_{zz}^T) \boldsymbol{\lambda}_z = \mathbf{g}_z$ using highly optimized LU decomposition. - Solve the symmetric systems $\mathbf{A} \boldsymbol{\lambda}_x = \mathbf{g}x - \mathbf{K}{zx}^T \boldsymbol{\lambda}_z$ and $\mathbf{A} \boldsymbol{\lambda}_y = \mathbf{g}y - \mathbf{K}{zy}^T \boldsymbol{\lambda}_z$ using the pre-factored Cholesky decomposition of
$\mathbf{A}$ .
To enforce the constructional constraint of flat quadrilateral panels, the coplanarization loss
The analytical partial derivatives of the volume
diff_soma/ # Git Repository Root
├── README.md # Scientific documentation & FDM formulations
├── LICENSE # MIT Open-source license
├── .gitignore # Git exclusion settings (excluding heavy binaries)
│
├── diff_soma/ # Rust Backend Library
│ ├── Cargo.toml
│ └── src/ (lib.rs, fdm.rs, adjoint.rs, optimizer.rs)
│
└── diff_soma_gh/ # C# .NET 8.0 Grasshopper Plugin
├── diff_soma_gh.csproj
├── diff_soma_ghComponent.cs
├── diff_soma_ghInfo.cs
└── sample/
└── soma_demo.gh # Pre-built interactive structural test case
To run the interactive Grasshopper parametric form-finding component inside Rhino 8/9, follow these steps:
- Download the pre-compiled library files
diff_soma_gh.ghaanddiff_soma.dllfrom the GitHub Releases page. - Open Rhino's Grasshopper components directory. You can easily access this by pressing
Win + Ron Windows, typing%appdata%\Grasshopper\Libraries, and pressing Enter. - Paste both
diff_soma_gh.ghaanddiff_soma.dlldirectly into that folder. - Launch Rhino 8 or Rhino 9, and open Grasshopper.
- In the Grasshopper tabs, navigate to the newly added Soma tab.
- Open the pre-built structural interactive demo file located at
diff_soma_gh/sample/soma_demo.ghand start tweaking the structural weights, self-weight coefficients, and target geometry parameters to witness real-time multi-objective adjoint form-finding.
The mathematical correctness of the analytical adjoint gradients has been verified against numerical gradients computed via Central Finite Differences. You can run the precision validation test suite using Cargo:
cargo testExpected output:
running 1 test
test tests::test_adjoint_precision_vs_finite_differences ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
While diff_soma provides a fast, lightweight, and mathematically complete solution for real-time CAD-integrated form-finding, several areas remain open for future development:
- Fully Sparse CSR Direct Solver: Integrating native sparse direct solver packages (such as
nalgebra-sparseorfaer-sparse) to accelerate non-symmetric system solves in larger structures. - Material Orthotropy: Modeling orthotropic shell and cable properties to extend the engine's physical accuracy to composite structures.
- Pneumatic Membrane & Cable-net Pre-stress Constraints: Extending the forward and adjoint solvers to handle enclosed volume constraints (pneumatics) to enable real-time air-supported structure form-finding.
- Comparative Performance Benchmarking: Conducting systematic comparative benchmarks against established structural optimization libraries in large-scale scenarios to evaluate runtime and convergence speed.
Developed with passion by Moamin
This project is licensed under the MIT License. See the LICENSE file for details.
