Hi all,
I’m experiencing an issue when trying to evaluate a function in parrallel.
Now I know it has been treated in previous tickets (Problem with evaluation at a point in parallel - #6 by MiroK , MPI - Gather and distribute a function to all processes (That I can evaluate at a point) - #3 by timwong …), but the thing I’m trying to understand here is why the following MWE works if we mark all the facets of the mesh and on only a subdomain.
mwe.py
import fenics as f
mesh = f.UnitSquareMesh(10, 10)
surface_markers = f.MeshFunction("size_t", mesh, 1, 0) # initialises all facets at zero
boundary_tag = 1
boundary = f.CompiledSubDomain("on_boundary && near(x[0], 0, tol)", tol=1e-14)
# boundary = f.CompiledSubDomain("on_boundary") # works fine with this!
boundary.mark(surface_markers, boundary_tag)
V = f.FunctionSpace(mesh, "CG", 1)
u = f.Function(V)
v = f.TestFunction(V)
T = f.interpolate(f.Constant(1), V)
F = f.inner(f.grad(u), f.grad(v))*f.dx
class CustomExpression(f.UserExpression):
def __init__(self, function, **kwargs):
super().__init__(kwargs)
self.function = function
def eval(self, value, x):
value[0] = 2*self.function(x) # this line hangs in parrallel
def value_shape(self):
return ()
expr = CustomExpression(T)
bc = f.DirichletBC(V, expr, surface_markers, boundary_tag)
f.solve(F==0, u, bcs=bc)
To reproduce the issue, run mpirun -np 2 python3 mwe.py
.
I wanted to know if there was a workaround.The function given in Problem with evaluation at a point in parallel - #6 by MiroK doesn’t seem to work.
Thanks!