Skip to main content

FluxFEM: A weak-form-centric differentiable finite element framework in JAX

Project description

PyPI version License: Apache-2.0 Python Version CI CI

FluxFEM

A weak-form-centric differentiable finite element framework in JAX

Examples and Features

Example 1: Diffusion Example 2: Neo Neohookean Hyper Elasticity
Diffusion-mms Neo-Hookean

Features

  • Built on JAX, enabling automatic differentiation and high-performance execution via grad, jit, vmap, and related transformations.

  • A FEM framework with a weak-form–centric API, emphasizing a smooth transition from theoretical formulations to practical code implementations.

  • Supports two assembly approaches: weak-form-based assembly and a tensor-based (scikit-fem–style) assembly.

  • enables to handle both Linear / Non-Linear analysis with AD in JAX

Usage

This library provides two assembly approaches.

  • A weak-form-based assembly, where the variational form is written and assembled directly.
  • A tensor-based assembly, where trial and test functions are represented explicitly as tensors and assembled accordingly (in the style of scikit-fem).
    The first approach offers simplicity and convenience, as mathematical expressions can be written almost directly in code. However, for more complex operations, the second approach can be easier to implement in practice. This is because the weak-form-based assembly is ultimately transformed into the tensor-based representation internally during computation.

weak-form-based assembly

import fluxfem as ff
import fluxfem.helpers_wf as h_wf

space = ff.make_hex_space(mesh, dim=3, intorder=2)
D = ff.isotropic_3d_D(1.0, 0.3)
bilinear_form = ff.BilinearForm.volume(
    lambda u, v, D: h_wf.ddot(v.sym_grad, D @ u.sym_grad) * h_wf.dOmega()
)
K_wf = space.assemble_bilinear_form(
    bilinear_form.get_compiled(),
    params=D,
)

tensor-based assembly (scikit-fem-style)

import fluxfem as ff
import numpy as np
import fluxfem.helpers_ts as h_ts

def linear_elasticity_form(ctx: ff.FormContext, D: np.ndarray) -> ff.jnp.ndarray:
        Bu = h_ts.sym_grad(ctx.trial)
        Bv = h_ts.sym_grad(ctx.test)
        return h_ts.ddot(Bv, D, Bu)


space = ff.make_hex_space(mesh, dim=3, intorder=2)
D = ff.isotropic_3d_D(1.0, 0.3)
K = space.assemble_bilinear_form(linear_elasticity_form, params=D)

Documentation

SetUp

You can install FluxFEM either via pip or Poetry.

Supported Python Versions

FluxFEM supports Python 3.11–3.13:

Choose one of the following methods:

Using pip

pip install fluxfem

Using poetry

poetry add fluxfem

Acknowledgements

I acknoldege everythings that made this work possible.

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

fluxfem-0.1.3a0.tar.gz (72.5 kB view details)

Uploaded Source

Built Distribution

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

fluxfem-0.1.3a0-py3-none-any.whl (87.8 kB view details)

Uploaded Python 3

File details

Details for the file fluxfem-0.1.3a0.tar.gz.

File metadata

  • Download URL: fluxfem-0.1.3a0.tar.gz
  • Upload date:
  • Size: 72.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for fluxfem-0.1.3a0.tar.gz
Algorithm Hash digest
SHA256 60410c881c9d79c03371e417e6cbe34438673ee88ca1107263b89b43491bb8fc
MD5 c3a413dbe971357a3f1b26b7e8f4824e
BLAKE2b-256 19ad8242a1dcc678d1cab20d68ba23033be1edcba6146569dff329942ad5095a

See more details on using hashes here.

File details

Details for the file fluxfem-0.1.3a0-py3-none-any.whl.

File metadata

  • Download URL: fluxfem-0.1.3a0-py3-none-any.whl
  • Upload date:
  • Size: 87.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for fluxfem-0.1.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa2641bb1b8a19c4402f4028a7e6531fe66ededf2355982d5ab5bd79d984aeb3
MD5 cd962bc8fb9c8a0f5900c47d44953e8f
BLAKE2b-256 29c04424e48f078da958eff83d5f6afa8eeb3b30a78d9b365820dcb6215bed7a

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