/VoxelFEM

Topology optimization framework for linear elasticity.

Primary LanguageC++MIT LicenseMIT

VoxelFEM

This is the codebase for our SCF 2022 paper, Efficient Layer-by-Layer Simulation for Topology Optimization. It includes a high-performance topology optimization code for linear elastic compliance minimization (using a multigrid preconditioned CG solver) as well as our algorithms for accelerating layer-by-layer simulation.

The code is written primarily in C++, but it is meant to be used through the Python bindings.

Getting Started

C++ Code Dependencies

The C++ code relies on Boost and CHOLMOD/UMFPACK, which must be installed separately.

The code also relies on MeshFEM, which is included as a submodule.

macOS

You can install all the mandatory dependencies on macOS with MacPorts.

# Build/version control tools, C++ code dependencies
sudo port install cmake boost ninja
sudo port install SuiteSparse +accelerate
# Dependencies for jupyterlab/notebooks
sudo port install python39
# Install nodejs/npm using nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
nvm install 17 && nvm use 17

If you use homebrew, you will need to link SuiteSparse to the Acceleration library manually. Use the command

brew rm suite-sparse
brew edit suite-sparse

and then remove the following three lines:

depends_on "openblas"
"BLAS=-L#{Formula["openblas"].opt_lib} -lopenblas",
"LAPACK=$(BLAS)",

Finally you will need to run brew reinstall --build-from-source suite-sparse for the changes to take effect.

Ubuntu 20.04

A few more packages need to be installed on a fresh Ubuntu 20.04 install:

# Build/version control tools
sudo apt install git cmake ninja-build
# Dependencies for C++ code
sudo apt install libboost-filesystem-dev libboost-system-dev libboost-program-options-dev libsuitesparse-dev
# Dependencies (pybind11, jupyterlab/notebooks)
sudo apt install python3-pip npm
sudo npm install npm@latest -g

Obtaining and Building

Clone this repository recursively so that its submodules are also downloaded:

git clone --recursive https://github.com/MeshFEM/VoxelFEM

Build the C++ code and its Python bindings using cmake and your favorite build system. For example, with ninja:

cd VoxelFEM
mkdir build && cd build
cmake .. -GNinja
ninja

Running the Jupyter Notebooks

The preferred way to interact with VoxelFEM is in a Jupyter notebook, using the Python bindings. We recommend that you install the Python dependencies and JupyterLab itself in a virtual environment (e.g., with venv).

pip3 install wheel # Needed if installing in a virtual environment
# Recent versions of jupyterlab and related packages cause problems:
#   JupyerLab 3.4 and later has a bug where the tab and status bar GUI
#                 remains visible after taking a viewer fullscreen
#   ipykernel > 5.5.5 clutters the notebook with stdout content
#   ipywidgets 8 and juptyerlab-widgets 3.0 break pythreejs
pip3 install jupyterlab==3.3.4 ipykernel==5.5.5 ipywidgets==7.7.2 jupyterlab-widgets==1.1.1
# If necessary, follow the instructions in the warnings to add the Python user
# bin directory (containing the 'jupyter' binary) to your PATH...

git clone https://github.com/jpanetta/pythreejs
cd pythreejs
pip3 install -e .
cd js
jupyter labextension install .

pip3 install matplotlib scipy

You may need to add the following to your shell startup script for the installation of pythreejs's dependencies during pip3 install -e . to succeed:

export NODE_OPTIONS=--openssl-legacy-provider;

Launch JupyterLab from the root python directory:

cd python
jupyter lab

Now try opening and running an demo notebook, e.g., python/3DTopoptDemo.ipynb.

Acknowledgements

We thank Michele Vidulis, Shad Durussel, and Vincent Pollet for their contributions to this multigrid topology optimization framework.