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.3.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.3-py3-none-any.whl (87.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fluxfem-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 a286ed166ea8c381e0069d2024c3015965692f693a2d3367f0de929d795a14b8
MD5 4d9fdfa7fe19d513ec8389bdfb966825
BLAKE2b-256 8af3606bfd37142e4b6c5dde675650ab0cf69788fd3f0dff7a73ce259ca9ab04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fluxfem-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 90029531062a93ff9f9fa25a8c70b3bc8bb968a0d517547cd8582c9a79c56aa8
MD5 c23d9411dbe98afc6f49869f921434d0
BLAKE2b-256 3972e0d201961e95fdd59acc765b8ec6dfedd274877825fcd59d598b26ffa71d

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