Multiple materials layout optimization in a layered structure