Saturday 1 May 2021

Simple implementation of a Physics-Informed Neural Networks in Pytorch for inverse problems

 https://colab.research.google.com/drive/1ycheGcblVg38FK662NzShspXudTE3ugg?usp=sharing

class Net_IP(nn.Module):

def __init__(self):
super(Net_IP, self).__init__()
self.input_layer_u = nn.Linear(2,100)
self.hidden_layer1 = nn.Linear(100,10)
self.output_layer_u = nn.Linear(10,1)
self.input_layer_mu = nn.Linear(1,10)
self.hidden_layer2 = nn.Linear(10,3)
self.output_layer_mu = nn.Linear(3,1)

def forward(self, x, t):
# temperature field
inputs_u = torch.cat([x,t],axis=1) # spatio-temporal coordinate
layer1_out = torch.sigmoid(self.input_layer_u(inputs_u))
layer2_out = torch.sigmoid(self.hidden_layer1(layer1_out))
output_u = self.output_layer_u(layer2_out)
# diffusion field
inputs_mu = x # spatial coordinate
layer3_out = torch.sigmoid(self.input_layer_mu(inputs_mu))
layer4_out = torch.sigmoid(self.hidden_layer2(layer3_out))
output_mu = torch.nn.functional.softplus(self.output_layer_mu(layer4_out))
# concatenation
output = torch.cat([output_u,output_mu],axis=1)
return output

net_IP = Net_IP()
net_IP = net_IP.to(device)

 

No comments:

Post a Comment