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 DOI

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 with grad, jit, vmap, and related transformations.
  • Weak-form–centric API that keeps formulations close to code; weak forms are represented as expression trees and compiled to element kernels.
  • Two assembly approaches: weak-form-based assembly and a tensor-based (scikit-fem–style) assembly.
  • Handles both linear and nonlinear analyses 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 Compile Flow

Weak-form expressions are compiled into an evaluation plan and then executed per element.

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, h_wf.matmul_std(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.4.tar.gz (76.0 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.4-py3-none-any.whl (91.3 kB view details)

Uploaded Python 3

File details

Details for the file fluxfem-0.1.4.tar.gz.

File metadata

  • Download URL: fluxfem-0.1.4.tar.gz
  • Upload date:
  • Size: 76.0 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.4.tar.gz
Algorithm Hash digest
SHA256 f95406f3f1bb4240cb5f42ab3fe5a20a6e0f881b5e08817a07993cb8ba5e8f6e
MD5 d2c16cb8d91456a0f99866834fd55a05
BLAKE2b-256 eeff077df18d5bae0ebdbff2278c004e04dfdd3e4718f0f7bf2536ca1c6e40d8

See more details on using hashes here.

File details

Details for the file fluxfem-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fluxfem-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 91.3 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7c15f4e5ab6db1749c64e37b62f257de3e77df5287929c60e17117b5f067db8b
MD5 17560c19ca11600bc17c94323612b96e
BLAKE2b-256 ca0a14a69f967f9ad5944932c872f32264a8868ec46a0f84fe7d97d5946aa5f8

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