mdai26 / PGNN

Polycrystal Graph Neural Network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graph Neural Network for Predicting the Effective Properties of Polycrystalline Materials

This repo contains the code base for the paper "Graph Neural Network for Predicting the Effective Properties of Polycrystalline Materials: A Comprehensive Analysis" by Minyi Dai, Mehmet F. Demirel, Xuanhan Liu, Yingyu Liang, Jiamian Hu.

Table of Contents

Prerequisites

Those packages can be installed in a new anaconda environment named pgnn through

conda create --name pgnn
conda activate pgnn
conda install python=3 scikit-learn pytorch==1.10.1 torchvision -c pytorch -c conda-forge

Data Generation

Data Generation

Polycrystal Microstructure Generation via Voronoi Tessellation

The 3D polygrain microstructure is generated through Voronoi Tessellation. The code can be found in the folder VoronoiGrain.

  • By default setting, 100 microstructures with the size of 64 x 64 x 64 can be generated through

    python datageneration.py
    
  • The parameters used for microstructure generation can be changed through revising Line #122-#138 of datageneration.py

    # set random seed
    random_seed = 10
    np.random.seed(random_seed)
    # specify the limit of number of grains
    lowerlimit = 10
    upperlimit = 400
    # specify number of microstructures
    ndata = 100
    # get the number of grain array
    ngrain = np.random.randint(lowerlimit, upperlimit, ndata, dtype=int)
    # define number of grain thickness
    gbwidth = 1
    # define dimension of the microstruture
    Nx = 64; Ny = 64; Nz = 64
    # define randome walk for grain center
    nrwalk = 10;
    # define use periodic boundary condition or not
    periodic = True
    
  • Introduction of output file

    • struct_${number}.in: document the structure id of each grid (0 for grain and 1 for grain boundary)

    • eulerAng_${number}.in: document the three euler angles of each grid

    • feature_${number}.txt: document the features of each grains

    • neighbor_${number}.txt: document the adjacency matrix of the microstructure

    • mark_and_newmark_${number}.vts: vtk file for plotting through ParaView, mark is the grain label and newmark is the structure id.

Polycrystal Microstructure Generation via Experimental Data

The code and instructions can be found in the folder experidata.

Materials Property calculation

Both the ionic conductivity and the Young's modulus are calculated through MuPro. The parameters can be found in the paper. Some scripts that help to run the simulation and collect the simulation results on Euler can be found in folder conductivity and elastic.

Available dataset

The datasets can be downloaded through this Link.

  • Microstructure - Conductivity Dataset with graph representation (suitable for Graph Neural Network):
    • GNNtraindata_unscaled.npz (training dataset with 4000 data points)
    • GNNvaliddata_unscaled.npz (validation dataset with 500 data points)
    • GNNtestdata_unscaled.npz (testing dataset with 500 data points)
    • Import the data
      GNNdata = np.load(filename)
      # node feature matrix
      nfeature = GNNdata['nfeature']
      # adjacency matrix
      neighblist = GNNdata['neighblist']
      # edge feature matrix
      efeature = GNNdata['efeature']
      # Target
      targetlist = GNNdata['targetlist']
      
  • Microstructure - Conductivity Dataset with image representation (suitable for Convolutional Neural Network)
    • CNNtraindata_unscaled.npz (training dataset with 4000 data points)
    • CNNvaliddata_unscaled.npz (validation dataset with 500 data points)
    • CNNtestdata_unscaled.npz (testing dataset with 500 data points)
    • Import the data
      CNNdata = np.load(filename)
      # 3D image 
      image = np.asarray(CNNdata['imagelist'])
      # target
      target = np.asarray(CNNdata['targetlist']
      
      Note that the CNN and GNN dataset are for the same 5000 raw data points. The data splits are also same for the two datasets
  • Microstructure - Young's Modulus dataset with graph representation
    • elasticdata.npz (the whole dataset with 604 data points)
    • Import the data
      GNNdata = np.load(filename)
      # node feature matrix
      nfeature = GNNdata['nfeature']
      # adjacency matrix
      neighblist = GNNdata['neighblist']
      # edge feature matrix
      efeature = GNNdata['efeature']
      # Target
      targetlist = GNNdata['targetlist']
      

Note that the input features of all the three datasets are normalized but the targets of all the three datasets are not normalized.

Polycrystal Graph Neural Network

The code of the PGNN model is developed based on the code of CGCNN model.

PGNN architecture

PGNN

Train a PGNN model

  • Put the following data and code in the same folder.
    • GNNtraindata_unscaled.npz
    • GNNvaliddata_unscaled.npz
    • GNNtestdata_unscaled.npz
    • main.py
    • model.py
    • data.py
  • Train the model from scratch
    • activate conda envirnoment if not
      conda activate pgnn
      
    • train the model from scratch (the default parameters are the optimized hyperparameters stated in the paper)
      python main.py
      

Available trained model weight

The available trained model weight using the microstructure-conductivity training dataset can be found through this link. Note that the targets of the dataset are min-max normalized to get the trainable weights.

To load the model weight

python main.py --load_model=checkpoint.pth.tar

Sequential Feature Selection

To perform the sequential feature selection, only minor changes of the code are needed. For example, for the first round of grain feature selection with the grain conductivity features, the 28th line of the code "data.py" need to be revised to the following

self.nfeature = np.array(nfeature)[:,:,7:]

Figure Plot

  • Plot the graph based on the data

    The microstructure graph can be plotted using the python package networkx. The code can be found in the folder Plot.

  • Plot the microstructure colored by orientation

    The code that convert the orientation to RGB colors can be found in the folder Plot. The obtained file 'grain20.vts' can be visualized using ParaView. Note that unchecking "Map Scalars" will visualize the microstructure based on the RGB colors.

License

PGNN is released under the MIT License.

About

Polycrystal Graph Neural Network

License:MIT License


Languages

Language:Python 98.9%Language:Shell 1.1%