Skip to content

eikehmueller/JaxMaterials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

169 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automated testing

JaxMaterials

High-performance Jax/CUDA-based library for differentiable materials modelling, designed to integrate physics-based models into modern machine learning workflows.

Enables gradient-based optimisation of ML surrogate models for material simulations, by combining efficient computation with scalable ML infrastructure which can run on CPUs and GPUs.

Goals

Materials with fine microstructure, such as carbon fibre composites, are expensive to simulate with classical PDE methods. Upscaling methods require a large number of simulations to infer distributions of material parameters. In addition, it is often desirable to provide

  • Sensitivity of output to input parameters
  • Support for running on CPU and GPU hardware

Machine learning surrogate models can reduce runtime but require:

Features

  • Differentiable materials models implemented in JAX
  • Automatic differentiation for optimisation and ML training
  • GPU acceleration of differentiable solvers via JAX
  • Bespoke CUDA solvers for data generation and inference
  • Modular design for extending models and components
  • Compatible with ML pipelines and optimisation frameworks

Achievements

The following figures compares the performance of the (an-) isotropic JAX and CUDA solvers when applied to an isotropic material.

Performance of JAX and CUDA solvers

Quick installation

Clone and run

pip install jaxmaterials

for the JAX-Python library. See detailed instructions below for CUDA support.

Contents

This repository contains the following code:

CUDA linear elasticity solver

A highly efficient CUDA accelerated solver of the linear elasticity equation in isotropic materials based on the Lippmann Schwinger method by [Moulinec and Suquet, 1998. Computer Methods in Applied Mechanics and Engineering, 157(1-2), pp.69-94].

Jax linear elasticity solver

A Jax implementation of the same method, which allows back-propagation through the solver for later use in a ML setting. Solvers for both isotropic and anisotropic materials have been implemented.

In addition to the plain Lippmann Schwinger solver, the code also supports Anderson acceleration as described in [Wicht, Schneider and Boehlke, T., 2021. International Journal for Numerical Methods in Engineering, 122(9), pp.2287-2311]. Since any Jax code is inherently differentiable, the solver can be used as a building block in a machine learning framework (see below).

Both solvers use the same discretisation as the AMITEX solver, which is described in [Gelebart 2020. Comptes Rendus. Mecanique, 348(8-9), pp.693-704]. For mathematical details see the ./doc subdirectory.

Fibre distribution generator

Code for sampling the Lame parameters which can be used as an input to the solvers. The generated samples contain cross-ply layers of fibres as shown in the following figure:

Generated fibres

ML toolchain (under construction)

A ML toolchain which uses the above code to train machine learning models that predict the efficient elasticity tensor for a given pair of Lame-parameter fields will be added later.

Installation

Prerequisites

The CUDA solver requires a working cuda installation, including the NVidia CUDA Toolkit which contains the NVidia CuFFT library. A working C++ compiler and CMake is required to compile and install the solver. To run the automated tests, the GoogleTest is required.

See pyproject.toml for a list of required Python packages.

Instructions

The following instructions should work on Linux machines, but will need to be adapted on Windows and Mac.

CUDA solver

  1. Clone this repository
  2. Change to the cuda subdirectory
  3. Configure in the build directory with
cmake -B build -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>

where <INSTALL_DIR> is the directory where the solver library should be installed. If the -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> is omitted, the default (usually /usr/lib/) is used, and you will likely need root access to install the library in this location.

  1. Build the solver with
cmake --build build
  1. (Optionally), if the google test framework is installed, test the library by running
./build/bin/test
  1. Install the library by running
cmake --install build
  1. Add the install directory to LD_LIBRARY_PATH to ensure that it can be loaded from Python
export LD_LIBRARY_PATH=<INSTALL_DIR>:${LD_LIBRARY_PATH}

Python library

In the main directory of the repository run

python -m pip install .

Optionally, add --editable flag for an editable install.

Run the tests suite with

python -m pytest

About

Jax / CUDA implementation of highly efficient solvers for the equations of linear elasticity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors