This repository contains the codes used for homogenization, ML-based desgin, and print path planning for the truss metamaterials presented in the manuscript:
Sharma et al., "Piezoelectric truss metamaterials: data-driven design and additive manufacturing", npj Metamaterials, 1, 9 (2025). DOI: 10.1038/s44455-025-00009-2
The corresponding dataset used in this work can be found under the following link: Dataset underlying the publication "Piezoelectric truss metamaterials: data-driven design and additive manufacturing"
Structure
│ LICENSE
│ README.md
│
├───data
│ Readme.md
│
├───deterministic-inverse-design
│ │ optimization.py
│ │ parameters.py
│ │ train.py
│ │
│ ├───data
│ │ Readme.md
│ │
│ └───src
│ errorAnalysis.py
│ lattice_utils.py
│ loadDataset.py
│ model_utils.py
│ normalization.py
│ voigt_rotation.py
│ __init__.py
│
├───generative-design
│ ├───data
│ │ Readme.md
│ │
│ ├───dataGeneration
│ │ generation.py
│ │ main.py
│ │ moveNodes.py
│ │
│ ├───fwdTrain
│ │ main.py
│ │ validation.py
│ │ __init__.py
│ │
│ ├───invOpt
│ │ invOpt_serial.py
│ │
│ ├───models
│ │ model.py
│ │ parameters.py
│ │ utils.py
│ │ __init__.py
│ │
│ └───results
│ best_e_model.pt
│ best_model.pt
│ e_model.pt
│ model.pt
│
├───print-path-opt
│ │ adjacency_table.m
│ │ Angle_bw_lines.m
│ │ bridge_check.m
│ │ checkPointOnSegment.m
│ │ directed_edges.m
│ │ DistBetween2Segment.m
│ │ edge_validation.m
│ │ endpointsofAonB.m
│ │ Fleurys_algorithm.m
│ │ gcode_write.m
│ │ GenEulerPath.m
│ │ intersection_point.m
│ │ is_valid.m
│ │ lattice_plot.m
│ │ linexline.m
│ │ Main.m
│ │ path_plot.m
│ │ RearrangeEdges.m
│ │ rotate_arbt_axis.m
│ │ sort_vertically.m
│ │ split_current_group.m
│ │ tessellate.m
│ │
│ ├───outputs
│ └───Unit_Cell_Coordinates
│ BaseUC7_UC.mat
│ BCC_loop_UC.mat
│ BCC_UC.mat
│ Bow_Tie_3D.mat
│ Cube_UC.mat
│ Octahedron_UC.mat
│ Octet_UC.mat
│
└───truss-homogenization-piezo
ang_ax.m
bluewhitered.m
calc_rad.m
corner_nodes.m
dof.m
edge_nodes.m
effective_piezo_surface.m
Effective_stiffness.m
effective_surface_plot.m
electric_field.m
e_rotation_tensor.m
face_nodes.m
fill_vec_map.m
fnalize_vec_map.m
Generate_Lattice.m
homogenization.m
identify_face_nodes.m
lattice_data.m
lattice_vectors.m
main.m
nodesInit.csv
PBC_mat.m
plotcube.m
ptb_mask.csv
remove_redundancy.m
rgsearch.m
rotate_arbt_axis.m
sanity_check_fem.m
ScaleToUnit.m
StiffnessMatrix.m
truss_plotting.m
This repository provides a framework to inversely design truss metamaterials with specific piezoelectric properties using deep learning. It extends the approach introduced in 'Inverting the structure-property map of truss metamaterials via deep learning' by enabling targeted optimization of piezoelectric truss structures.
train.py: Trains a neural network to learn the relationship between truss structures and their material properties.optimization.py: Uses the trained network to optimize truss metamaterials for specific piezoelectric properties.
The train.py script trains a deep learning model to predict the mechanical properties of truss metamaterials based on their structure. This script should be used if you need to retrain the network from scratch, e.g., to adapt the framework to new datasets or refine performance.
python train.pyThe optimization.py script utilizes the trained network to inversely design trusses that exhibit desired piezoelectric properties.
python optimization.py <objective><objective>: Specifies the target property to optimize (e.g., maximizing or minimizing specific piezoelectric components). Refer to the code to use/add new objectives
The optimized truss designs will be stored in the results/ directory in .csv format. These files contain the optimized structural parameters required to achieve the specified properties.
- Python (tested on version 3.7+)
- Python packages:
- PyTorch (CUDA-supported version recommended)
- Pandas
- NumPy
- Matplotlib (optional, for visualization)
All codes were adapted from the original publication:
https://github.com/jhbastek/InvertibleTrussDesign
This repository provides a generative modeling framework for constructing a unified design space for inverse design with truss lattices, as described in 'Unifying the design space and optimizing linear and nonlinear truss metamaterials by generative modeling'. The framework is adapted from 'Zheng et al. (2023)' and enables both forward property prediction and inverse design optimization of truss structures with tailored piezoelectric properties.
The main.py script trains the generative modeling framework and the property predictor using the provided dataset. This script should be run if you need to retrain the models from scratch.
python main.pyThe validation.py script loads the pre-trained models and performs the following tasks:
- Predicts the reconstructed truss structures and their corresponding effective piezelectric matrices for a test dataset.
- Randomly samples 1000 points from a multivariate Gaussian distribution and calculates the validity score.
python validation.pyThe invOpt.py script enables inverse design of truss structures with desired piezoelectric properties using gradient-based optimization.
python invOpt.py <objective> <seed>-
<objective>: Specifies the target piezoelectric matrix component to optimize (e.g., maximizing or minimizing specific components such as$e_{15}$ ,$e_{31}$ , etc.)
To optimize for maximizing the piezoelectric component (e_{15}) with random seed=1, run the following:
python invOpt.py +e15 1- Python (tested on version 3.10.4)
- Python packages:
- PyTorch (tested on CUDA version 11.0)
- Pandas
- NumPy
- SciPy
All codes were adapted from the original publication: https://github.com/li-zhengz/UnifyingTrussDesignSpace
The codes used for homogenizing the truss unit cells for thier effective properties are contained in truss-homogenization-piezo/
main.m--- Generates the dataset for ML training by homogenizing trusses of dataset I and dataset II for electromechanical properties.- For dataset I, the unit cell geometries and topologies are generated by processing the input features strored in
data/input_DS1.mat. - For dataset II, the geometry and topologies are stored in
data/nodes_DS2.matanddata/connect_DS2.mat.
Codes utilized for the graph-based print path planning of the lattices are contained in print-path-opt/ (based on the graph theory-based approach of Weeks et al.)
Ref: Weeks, R. D., Truby, R. L., Uzel, S. G. & Lewis, J. A. Embedded 3D printing of multimaterial polymer lattices via graph-based print path planning. Adv. Mater. 35, 2206958 (2023).
-
main.m- Loads coordinates and the connectivity of the lattice to be printed from
print-path-opt/Unit_Cell_Coordinates/. - Generates
pathfor the lattice with the sequence of nodes to be followed (includes both travel and printing motions).
- Loads coordinates and the connectivity of the lattice to be printed from
-
gcode_write.m- Can be used as a function with
main.mto generate g-code from the variablespathandlattice_coordsor from a separate file containing path and coordinates. - Creates a
.txtfile with g-code coordinates for travel and printing motions. - Printing and extrusion parameters can be tuned to adjust for the printer specifications used.
- Saves g-codes to
print-path-opt/outputs/.
- Can be used as a function with
To generate the path for an octet lattice with a 2×2×2 tessellation:
- Load
Unit_Cell_Coordinates/Octet_UC.mat. - Set
tess = [2,2,2]. - Run
Main.m. - The coordinates of the points in the G-code format will be written to a
.txtfile and saved to'print-path-opt/outputs/'.
The "Start G-code" and "End G-code" lines, specific to the printer being used, can be added to the.txtfile.
Finally, rename the file with a.gcodeextension to use it for printing.