Research Article

Fast and Accurate Numerical Solution of Allen–Cahn Equation

Algorithm 1

Our CNN model for solving AC equation (6).
class Net (nn.Module):
 def __init__(self, h2, dt, eps, device):
  super (Net, self).__init__()
  # 2nd order differencing filter
  self.lap = torch.Tensor ([[[[0., 1., 0.], [1., −4., 1], [0., 1., 0.]]]]).to (device)
  self.pad = nn.ReplicationPad2d (1) #Replication pad for boundary condition.
  self.alpha = dt/eps 2
  self.beta = dt/h2
 def forward (self, x):
  u_pad = self.pad (x) #boundary condition
  reaction = F.conv2d (u_pad, self.lap) #reaction term
  x = (1 + self.alpha) x-self.alpha x 3 + self.beta reaction
  return x