I have a problem where I want to solve a PDE on multiple inputs. For example, suppose we have the Poisson equation (copied below from docs):
from fenics import *
# Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)
# Define boundary condition
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, u_D, boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx
# Compute solution
u = Function(V)
solve(a == L, u, bc)
But I wish to feed in a batch of f
, for example 100 different values, and solve the PDE for those inputs. Currently, I’m doing this by iterating sequentially over the 100 values. I have already tried using multiprocessing, but this is not compatible with autograd. Is there no way of feeding in an input with a batch dimension? In the end FEniCS is carrying out linear algebra, and implementations normally have support for this kind of thing.