############################################################################### Title: Inverse design of anisotropic spinodoid materials with prescribed diffusivity Authors: Magnus Röding, Victor Wåhlstrand Skärström, Niklas Lorén Description: Dataset and code used in M Röding, et al, "Inverse design of anisotropic spinodoid materials with prescribed diffusivity", published in Scientific Reports. In this work, we develop a framework for inverse design of a class of anisotropic materials with spinodoid i.e. spinodal decomposition-like morphology, where the structure is optimized to have prescribed diffusivity. We use a convolutional neural network (CNN) for predicting effective diffusivity in all three directions. The CNN is used in an approximate Bayesian computation (ABC)-based formulation of the inverse problem. Herein, the codes in Matlab and Python/Tensorflow for structure generation, prediction and inverse design are supplied, together with the dataset and the trained CNN model. The parts that require the proprietary code for lattice Boltzmann simulations of diffusion are not included. ############################################################################### Begin by unzipping all compressed files. ------------------------------------------------------------------------------- Requirements ------------------------------------------------------------------------------- The Matlab code is tested in Matlab R2021b and requires Parallel Computing Toolbox, Image Processing Toolbox, Deep Learning Toolbox, and Statistics and Machine Learning Toolbox. Further, to import the CNN from HDF5 (TensorFlow) format to Matlab format, the Deep Learning Toolbox Converter for TensorFlow Models is required. The Python/Tensorflow code is tested in Python 3.9.6 (Anaconda distribution) and Tensorflow 2.6.0. Numpy is also required. ------------------------------------------------------------------------------- Data ------------------------------------------------------------------------------- The data is generated using Matlab (for structure generation) and proprietary software (for diffusion simulation). The data used is in the 'data' folder. In the subfolders 'train', 'val', and 'test', the structures and the corresponding diffusivities are stored in individual MAT files. The data are converted to Python/Numpy-compatible raw, binary BIN format using 'mat2bin_structures.m' and 'mat2bin_diffusivity.m'. The resulting files are already included in this repository. ------------------------------------------------------------------------------- Structure generation ------------------------------------------------------------------------------- The code for generating structures is in the 'structure' folder. It can be tested by running 'run_structure.m'. Random structure parameters are sampled from the prior distribution in 'sample_parameters.m'. In 'generate_structure.m', the structure is generated. The connectivity conditions are checked in 'check_connectivity.m'; if they are not satisfied, an empty array will be returned instead of a structure. ------------------------------------------------------------------------------- Prediction ------------------------------------------------------------------------------- Training and prediction is performed in Python/Tensorflow using some helper scripts in Matlab. The code for training the prediction model is in 'prediction'. Training is performed in 'train.py'. Data loading and preprocessing is performed in 'data.py' and 'processing.py'. The CNN model and its learning rate schedule are defined in 'cnn_model.py'. The results of the training are stored in 'training' in separate files for losses, parameters/metadata, and the model itself. If several training runs are performed, 'consolidate_training_results.m' can be used to identify the best run and copy those files to 'model'. The model used in the paper is supplied herein. The performance of the predictions is assessed by running 'extract_results.m', which computes MSE (mean squared error) and MAPE (mean absolute percentage error) losses for all individual parameters. The prediction results are stored in 'results.mat'. The model can be converted to a Matlab compatible model using 'cnn2mat.m' (this step requires the Deep Learning Toolbox Converter for TensorFlow Models). ------------------------------------------------------------------------------- Optimization/inverse design ------------------------------------------------------------------------------- Optimization/inverse design of structures to obtain prescribed properties is perfomed in Matlab. The code is in 'optimization' and started by running 'run.m'. The two target diffusivity vectors used in the paper are found here. The ABC framework will attempt to iteratively improve the approximation of the posterior distribution by putting increasingly tighter constraints on the difference between the target diffusivity and the obtained diffusivities. The number of iterations is currently 9 (plus and controlled by the threshold sequence tau. Intermediate results are saved in 'results' after each iteration is completed.