Skip to main content

Lego-like building blocks for differentiable finite element analysis

Project description

drawing

Tatva (टत्तव) : Lego-like building blocks for differentiable FEM

tatva (is a Sanskrit word which means principle or elements of reality). True to its name, tatva provide fundamental Lego-like building blocks (elements) which can be used to construct complex finite element method (FEM) simulations. tatva is purely written in Python library for FEM simulations and is built on top of JAX ecosystem, making it easy to use FEM in a differentiable way.

Documentation Tests

License

tatva is distributed under the GNU Lesser General Public License v3.0 or later. See COPYING and COPYING.LESSER for the complete terms. © 2025 ETH Zurich (SMEC).

Features

  • Energy-based formulation of FEM operators with automatic differentiation via JAX.
  • Capability to handle coupled-PDE systems with multi-field variables, KKT conditions, and constraints.
  • Element library covering line, surface, and volume primitives (Line2, Tri3, Quad4, Tet4, Hex8) with consistent JAX-compatible APIs.
  • Mesh and Operator abstractions that map, integrate, differentiate, and interpolate fields on arbitrary meshes.
  • Automatic handling of stacked multi-field variables through the tatva.compound utilities while preserving sparsity patterns.

Installation

Install the current release from PyPI:

pip install tatva

For development work, clone the repository and install it in editable mode (use your preferred virtual environment tool such as uv or venv):

git clone https://github.com/smec-ethz/tatva.git
cd tatva
pip install -e .

Documentation

Available at smec-ethz.github.io/tatva-docs. The documentation includes API references, tutorials, and examples to help you get started with tatva.

Usage

Create a mesh, pick an element type, and let Operator perform the heavy lifting with JAX arrays:

import jax.numpy as jnp
from tatva.element import Tri3
from tatva.mesh import Mesh
from tatva.operator import Operator

coords = jnp.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
elements = jnp.array([[0, 1, 2], [0, 2, 3]])

mesh = Mesh(coords, elements)

op = Operator(mesh, Tri3())
nodal_values = jnp.arange(coords.shape[0], dtype=jnp.float64)

# Integrate a nodal field over the mesh
total = op.integrate(nodal_values)

# Evaluate gradients at all quadrature points
gradients = op.grad(nodal_values)

Examples for various applications will be added very soon. They showcase patterns such as mapping custom kernels, working with compound fields, and sparse assembly helpers.

Dense vs Sparse vs Matrix-free

A unique aspect of tatva is that it can handle construct dense matrices, sparse matrices, and matrix-free operators. tatva uses matrix-coloring algorithm and sparse differentiation to construct a sparse matrix. We use our own coloring library tatva-coloring to color a matrix based on sparsity pattern, one can use other coloring libraries such as pysparsematrixcolorings for more advanced coloring algorithms. This significantly reduces the memory consumption. For large problems, we can also use matrix-free operators which do not require storing the matrix in memory. Since we have a energy functional, we can make use of jax.jvp ti compute the matrix-vector product without explicitly forming the matrix. This is particularly useful for large problems where storing the matrix is not feasible.

Paper

To know more about tatva and how it works please check: (arXiv link)

👉 Where to contribute

If you have a suggestion that would make this better, please fork the repo and create a pull request on github.com/smec-ethz/tatva. Please use that repository to open issues or submit merge requests. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

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

tatva-0.10.1.tar.gz (512.2 kB view details)

Uploaded Source

Built Distribution

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

tatva-0.10.1-py3-none-any.whl (83.5 kB view details)

Uploaded Python 3

File details

Details for the file tatva-0.10.1.tar.gz.

File metadata

  • Download URL: tatva-0.10.1.tar.gz
  • Upload date:
  • Size: 512.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tatva-0.10.1.tar.gz
Algorithm Hash digest
SHA256 91d46b1b3dc2896fe49a94ddcc4ea97e7ec0fdf65c4ae77a834c6373f8c93f73
MD5 d540c1106de639c6b21d23031a07a7e1
BLAKE2b-256 777681c287084fca4204deee63c4224fe852016a73ccf14d986a8cf2b8c74d24

See more details on using hashes here.

File details

Details for the file tatva-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: tatva-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 83.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tatva-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d314bd2eae3bc1775a6433a5bc15f08eede9af2c839602c9b99b4a405d4b3345
MD5 bab044710adf96c5c5f7a3aec245f7db
BLAKE2b-256 4916ff14b6b6d658bcb20aa65835bdae96ddd76f9a2a061b8531b35d652c6e53

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