随机2D形状周围层流预测!基于飞桨实现图形神经网络
发布日期:2023-06-15 16:00浏览量:393次
论文原文
原文代码
message_input = paddle.concat([node_features, grad_P1], axis=1)
updated = message_fn(message_input)
return updated
n_nodes = paddle.to_tensor(node_features.shape[0])
n_features = paddle.to_tensor(node_features.shape[1])
reshaped = paddle.reshape(node_features[edges], shape=[-1, 2 * n_features])
symmetric = 0.5 * paddle.add(reshaped[:, 0:n_features], reshaped[:, n_features:2 * n_features])
asymmetric = 0.5 * paddle.abs(paddle.subtract(reshaped[:, 0:n_features],
reshaped[:, n_features:2 * n_features]))
inputs = paddle.concat([symmetric, asymmetric, edge_features], axis=1)
messages = message_fn(inputs) # n_edges, n_output
n_edges = edges.shape[0]
updates = paddle.slice(
paddle.add(paddle.index_add_(paddle.zeros([n_edges, messages.shape[1]]), edges[:, 0], 0, messages),
paddle.index_add_(paddle.zeros([n_edges, messages.shape[1]]), edges[:, 1], 0, messages)),
axes=[0, 1], starts=[0, 0], ends=[n_nodes, messages.shape[1]])
return messages, updates
def __init__(self):
super(EdgeSmoothing, self).__init__()
def forward(self, to_concat, node_features, edges, count):
n_nodes = paddle.to_tensor(node_features.shape[0])
flow_on_edge = paddle.mean(node_features[edges], axis=1)
aggre_flow = paddle.add(paddle.index_add_(paddle.zeros([edges.shape[0], flow_on_edge.shape[1]]), edges[:, 0], 0,flow_on_edge[:, :]),
paddle.index_add_(paddle.zeros([edges.shape[0], flow_on_edge.shape[1]]), edges[:, 1], 0,flow_on_edge[:, :]))
return paddle.concat([to_concat, paddle.divide(aggre_flow[:n_nodes, :], count)], axis=1)
def __init__(self, edge_feature_dims, num_filters, initializer):
super(InvariantEdgeModel, self).__init__()
self.edge_feat_dims = edge_feature_dims
self.num_filters = num_filters
self.initializer = initializer
self.layer0 = InvariantEdgeConv(self.edge_feat_dims[0], self.num_filters[0], self.initializer)
self.layer1 = InvariantEdgeConv(self.edge_feat_dims[1], self.num_filters[1], self.initializer)
self.layer2 = InvariantEdgeConv(self.edge_feat_dims[2], self.num_filters[2], self.initializer)
self.layer3 = InvariantEdgeConv(self.edge_feat_dims[3], self.num_filters[3], self.initializer)
self.layer4 = InvariantEdgeConv(self.edge_feat_dims[4], self.num_filters[4], self.initializer)
self.layer5 = InvariantEdgeConv(self.edge_feat_dims[5], self.num_filters[5], self.initializer)
self.layer6 = InvariantEdgeConv(self.edge_feat_dims[6], self.num_filters[6], self.initializer)
self.layer7 = InvariantEdgeConv(self.edge_feat_dims[7], self.num_filters[7], self.initializer)
self.layer8 = nn.Linear(10, 3)
self.smoothLayer = EdgeSmoothing()
def forward(self, node_input, edges, edge_input, smoothing_weights):
new_node_features_0, new_edge_features_0 = self.layer0(node_input, edge_input, edges)
smoothed_0 = self.smoothLayer(node_input[:, 0:2], new_node_features_0, edges, smoothing_weights)
new_node_features_1, new_edge_features_1 = self.layer1(smoothed_0, new_edge_features_0, edges)
smoothed_1 = self.smoothLayer(node_input[:, 0:2], new_node_features_1, edges, smoothing_weights)
new_node_features_2, new_edge_features_2 = self.layer2(smoothed_1, new_edge_features_1, edges)
smoothed_2 = self.smoothLayer(node_input[:, 0:2], new_node_features_2, edges, smoothing_weights)
new_node_features_3, new_edge_features_3 = self.layer3(smoothed_2, new_edge_features_2, edges)
smoothed_3 = self.smoothLayer(node_input[:, 0:2], new_node_features_3, edges, smoothing_weights)
new_node_features_4, new_edge_features_4 = self.layer4(smoothed_3, new_edge_features_3, edges)
smoothed_4 = self.smoothLayer(node_input[:, 0:2], new_node_features_4, edges, smoothing_weights)
new_node_features_5, new_edge_features_5 = self.layer5(smoothed_4, new_edge_features_4, edges)
smoothed_5 = self.smoothLayer(node_input[:, 0:2], new_node_features_5, edges, smoothing_weights)
new_node_features_6, new_edge_features_6 = self.layer6(smoothed_5, new_edge_features_5, edges)
smoothed_6 = self.smoothLayer(node_input[:, 0:2], new_node_features_6, edges, smoothing_weights)
new_node_features_7, new_edge_features_7 = self.layer7(smoothed_6, new_edge_features_6, edges)
smoothed_7 = self.smoothLayer(node_input[:, 0:2], new_node_features_7, edges, smoothing_weights)
node_outputs = self.layer8(smoothed_7[:, 0:])
return node_outputs
项目结果
为了展示复现的效果,我们使用复现模型对圆柱流场进行预测,结果如下:
图2 预测效果对比图
往期推荐
体验AI
Web端 前往AI能力体验中心
移动端 打开百度APP“扫一扫”