Hello,
I am trying t solve a diffusion problem (Please find the image) in which I want to apply a boundary condition at a point. I have found the discussion regarding this, but it was implemented in FEniCS, I want the solution in FEniCSx.
I have tried something like this but it doesn’t work out.
mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 2, 2)
boundaries_2 = [(5, lambda x: np.isclose([x[0], x[1]], [0, 0]))]
facet_indices_2, facet_markers_2 = [], []
fdim_2 = mesh.topology.dim - 2
for (marker, locator) in boundaries_2:
facets_2 = dolfinx.mesh.locate_entities(mesh, fdim_2, locator)
facet_indices_2.append(facets_2)
facet_markers_2.append(np.full(len(facets_2), marker))
facet_tag_2 = dolfinx.MeshTags(mesh, fdim_2, np.array(np.hstack(facet_indices_2),dtype=np.int32), np.array(np.hstack(facet_markers_2),dtype=np.int32))
It threw this error.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_65/458078783.py in <module>
2 fdim_2 = mesh.topology.dim - 2
3 for (marker, locator) in boundaries_2:
----> 4 facets_2 = dolfinx.mesh.locate_entities(mesh, fdim_2, locator)
5 facet_indices_2.append(facets_2)
6 facet_markers_2.append(np.full(len(facets_2), marker))
/usr/local/dolfinx-real/lib/python3.8/dist-packages/dolfinx/mesh.py in locate_entities(mesh, dim, marker)
41 """
42
---> 43 return cpp.mesh.locate_entities(mesh, dim, marker)
44
45
/tmp/ipykernel_65/2253244396.py in <lambda>(x)
----> 1 boundaries_2 = [(5, lambda x: np.isclose([x[0], x[1]], [0, 0]))]
<__array_function__ internals> in isclose(*args, **kwargs)
/usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
2356 yfin = isfinite(y)
2357 if all(xfin) and all(yfin):
-> 2358 return within_tol(x, y, atol, rtol)
2359 else:
2360 finite = xfin & yfin
/usr/local/lib/python3.8/dist-packages/numpy/core/numeric.py in within_tol(x, y, atol, rtol)
2337 def within_tol(x, y, atol, rtol):
2338 with errstate(invalid='ignore'):
-> 2339 return less_equal(abs(x-y), atol + rtol * abs(y))
2340
2341 x = asanyarray(a)
ValueError: operands could not be broadcast together with shapes (2,9) (2,)
Please tell, how can I implement this.
Thank you